繁体   English   中英

如何在 arduino 字符串中找到 \n 的数量

[英]How to find the amount of \n in an arduino String

我试图在我的 arduino 的字符串中找到 \n 的索引。 这是我正在使用的代码:

String string = data;
int del;
int count = 0;
while(true){
  if(string.indexOf("\n", (del + 1)) == -1){
    break;
    }
  else{
    del = string.indexOf("\n", (del + 1));
    count++;
    }
  }

无论出于何种原因,无论如何它都只是返回 0 。 我的目标是让 count 变量包含变量中包含的行数。 任何建议都会很棒。

您需要初始化int del=-1

除此之外,我看不出有什么问题。 可能是您可能需要使用像这样的单引号'\n' ,表示一个字符而不是双引号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM