如何在Arduino的匹配字符串文本 [英] How to match text in string in Arduino
本文介绍了如何在Arduino的匹配字符串文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对如何匹配文本的一些问题与Arduino的。
我有:
字符串TMP = + CLIP:37011111111,145,,,,0
和我想匹配:
如果(tmp.startsWith(+ CLIP:)){
mySerial.println(ATH0);
}
但是,这是不工作的,我不知道为什么。
我试过串
,但结果是一样的。我不知道如何使用它,或者什么也不会发生。
哪里错误?
解决方案
BOOL包含(字符串s字符串搜索){
INT最大= s.length() - search.length(); 的for(int i = 0; I< = MAX;我++){
如果(s.substring(我)==搜索)返回true; //或者我
} 返回false; //或-1
}
另外,你可以简单地做:
如果(readString.indexOf(+ CLIP:)> = 0)
我也建议您访问:
https://www.arduino.cc/en/Reference/String
I have some issues with Arduino about how to match text.
I have:
String tmp = +CLIP: "+37011111111",145,"",,"",0
And I am trying to match:
if (tmp.startsWith("+CLIP:")) {
mySerial.println("ATH0");
}
But this is not working, and I have no idea why.
I tried substring
, but the result is the same. I don't know how to use it or nothing happens.
Where is the error?
解决方案
bool Contains(String s, String search) {
int max = s.length() - search.length();
for (int i = 0; i <= max; i++) {
if (s.substring(i) == search) return true; // or i
}
return false; //or -1
}
Otherwise you could simply do:
if (readString.indexOf("+CLIP:") >=0)
I'd also recommend visiting:
https://www.arduino.cc/en/Reference/String
这篇关于如何在Arduino的匹配字符串文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文