8
Answers

Trouble Parsing with Indexof

Ask a question
Telco Joe

Telco Joe

13y
2.1k
1
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)