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)
Loading
Sam HobbsPosted Nov 18, 2010, 8:39 PM
Telco JoePosted Nov 18, 2010, 7:25 PM
Sam HobbsPosted Nov 17, 2010, 11:11 PM
Telco JoePosted Nov 17, 2010, 10:07 PM
Sam HobbsPosted Nov 17, 2010, 9:00 PM
Telco JoePosted Nov 17, 2010, 8:04 PM
Sam HobbsPosted Nov 17, 2010, 6:59 PM
Zoran HorvatPosted Nov 17, 2010, 6:35 PM
Can you post a bit more code to show how variable data is obtained. Also, it would be good if you had logged or printed to console input and output strings (data and results), so to catch the case in which result is incorrect.
One hint - you haven't checked whether @ and # exist in data or not.