如何在Arduino中匹配字符串中的文本 [英] How to match text in string in Arduino
本文介绍了如何在Arduino中匹配字符串中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 Arduino 有一些关于如何匹配文本的问题.
I have some issues with Arduino about how to match text.
我有:
String tmp = +CLIP: "+37011111111",145,"",,"",0
我正在尝试匹配:
if (tmp.startsWith("+CLIP:")) {
mySerial.println("ATH0");
}
但这不起作用,我不知道为什么.
But this is not working, and I have no idea why.
我试过substring
,但结果是一样的.我不知道如何使用它,否则什么也不会发生.
I tried substring
, but the result is the same. I don't know how to use it or nothing happens.
错误在哪里?
推荐答案
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
}
否则你可以简单地做:
if (readString.indexOf("+CLIP:") >=0)
我还建议您访问:
https://www.arduino.cc/en/Reference/String
这篇关于如何在Arduino中匹配字符串中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文