如何从下面的字符串中提取权重值?
[GET / weight / 250 / HTTP / 1.1主机:192.168.1.2:8080连接:保持活跃]
我如何需要它留下来:
float weight = 250
答案 0 :(得分:0)
在Arduino中,您可以使用substring函数,后跟toFloat函数:
void setup() {
// put your setup code here, to run once:
}
void loop() {
String stringOne = "[GET /weight/250/ HTTP/1.1 Host: 192.168.1.2:8080 Connection: Keep-Alive]";
String stringTwo = stringOne.substring(13, 16);
float weight = stringTwo.toFloat();
// do nothing while true:
while (true);
}