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

Zoran HorvatRank #792 · 2.9K reputationPosted Nov 17, 2010, 1:35 PM EST
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.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 17, 2010, 1:59 PM EST
Telco Joe7 reputationPosted Nov 17, 2010, 3:04 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Nov 17, 2010, 4:00 PM EST
Telco Joe7 reputationPosted Nov 17, 2010, 5:07 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Nov 17, 2010, 6:11 PM EST
Telco Joe7 reputationPosted Nov 18, 2010, 2:25 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Nov 18, 2010, 3:39 PM EST