Arduino:从字符串中提取单词并将其传递给float变量

时间:2017-05-26 00:59:47

标签: c++ arduino

如何从下面的字符串中提取权重值?

  

[GET / weight / 250 / HTTP / 1.1主机:192.168.1.2:8080连接:保持活跃]

我如何需要它留下来:

float weight = 250

1 个答案:

答案 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);
}