By ErgonomicGrip


2020-05-22 23:46:11 8 Comments

I'm trying to find the indexes of \n in a string on my arduino. This is the code i'm using:

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++;
    }
  }

For whatever reason, it's just returning 0 no matter what. My goal would be for the count variable to contain the amount of lines contained in the variable. Any advice would be great.

1 comments

@Mithil Poojary 2020-05-23 00:28:01

You need to initialize int del=-1.

Other than that, I don't see a problem. Could be that you might need to use single quotes like this '\n', indicating a character and not double quotes.

Related Questions

Sponsored Content

25 Answered Questions

[SOLVED] How to convert std::string to lower case?

78 Answered Questions

[SOLVED] How do I iterate over the words of a string?

  • 2008-10-25 08:58:21
  • Ashwin Nanjappa
  • 2176705 View
  • 2982 Score
  • 78 Answer
  • Tags:   c++ string split

27 Answered Questions

[SOLVED] Easiest way to convert int to string in C++

28 Answered Questions

[SOLVED] How do you set, clear, and toggle a single bit?

8 Answered Questions

[SOLVED] How to convert a std::string to const char* or char*?

  • 2008-12-07 19:30:56
  • user37875
  • 926292 View
  • 891 Score
  • 8 Answer
  • Tags:   c++ string char const

19 Answered Questions

[SOLVED] How can I profile C++ code running on Linux?

  • 2008-12-17 20:29:24
  • Gabriel Isenberg
  • 522150 View
  • 1813 Score
  • 19 Answer
  • Tags:   c++ linux profiling

5 Answered Questions

1 Answered Questions

Finding the position of a symbol in unsigned char and extracting contents between indexes?

  • 2017-09-29 08:11:51
  • fuzzybabybunny
  • 42 View
  • 0 Score
  • 1 Answer
  • Tags:   c++ arduino

1 Answered Questions

Need help getting value from html slider on yun to arduino value

Sponsored Content