c++ - Arduino 将字符串拆分为带分隔符的数组

标签 c++ arduino

下面是一个简单的代码,用于从我的功率分析仪读取输入数据,我使用的是 gizduino+ ATMEGA 644p,它是一个 arduino 克隆。

void setup() {
    Serial.begin(9600);  
String str;
void loop() {

if(Serial.available() > 0)
{
    str = Serial.readStringUntil('\n');
    Serial.println(str);
 } 
}

您在下面看到的是我的串行监视器中的输出,我是 arduino 编程的新手,我的问题是我需要获取第三个索引,如果它是一个用逗号分隔的数组。

InRange, 0000.0,0000.0, 0000.0, 0.1055,229.39,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.1267,228.99,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.0633,229.00,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.0914,229.31,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.1126,228.88,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.0914,229.29,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.1055,229.34,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.1267,229.25,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.1041,230.03,0.0006,
InRange, 0000.0,0000.0, 0000.0, 0.0277,229.79,0.0006,

最佳答案

这里已经有很多答案了:

https://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string

没有像 python 或 javascript 那样直接的方法。您需要解析字符串,直到字符显示为止。

关于c++ - Arduino 将字符串拆分为带分隔符的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728931/

相关文章:

c++ - 如何在卸载 DLL 或进程终止时释放资源

c++ - 如何轻松地将函数应用于 C++ 中的集合

c++ - 什么是虚拟适配器

Arduino - millis() - 获取其他变量值的值

c++ - Arduino 在循环中显示 LED 输出的奇怪行为

c - Arduino myFile.write(buff, len) 不起作用

c++ - 将指针参数传递给双指针参数

c++ - 如何从类模板自身的类定义中引用类模板作为模板?

c++ - 在 C++ 中迭代指向实例的指针数组所需的声明

c++ - : expected constructor,析构函数错误,或者 '=' toke之前的类型转换