Telco Joe

Telco Joe

  • NA
  • 7
  • 2.4k

Trouble Parsing with Indexof

Nov 17 2010 3:45 PM
I am trying to use indexof to parse serial data and extract data between @ and #.

int start = data.IndexOf('@') + 1;
int end = data.IndexOf('#', start);
string result = data.substring (start, end - start -1)

but sometimes the string does not stop at # and I get extra data. What is a good way to effectively filter out everything outside of the @ and #.

Note: If the data being processed is from a pre-existing string, then it works fine. The problem is when the data comes in from a serial port (stream)


Answers (8)