Parsing a stream of data

I have a program that is reading in a stream of data every 2 seconds or so.


I want to accumulate the data into a string variable...then work on it at my leisure.

The reason for this is the data coming in is not a "complete" record.

Sometimes it may take 2 or 3 readings to get a full record.

I only want to parse full records.  If I try and parse partial records my tokenizer will fail.

Full records start with &&   and  end with  !!



Suggestions?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
existenz2Connect With a Mentor Commented:
This example is based upon reading a textfile but also can be used for other streams. Since I have no idea about your record layout. I just assumed that all records between the "&&" and "!!" are put in a string seperated with "\n".

StreamReader sr = new StreamReader(configfile);
string line = null;
string record = null;
while((line = sr.ReadLine()) != null)
{
// Start of record
if(line.StartsWith("&&")) {
 record = line;
}
// End of record
else if(line.StartsWith("!!")) {
 //do something with the record
}
// Record value
else {
record += line;
}
}
0
 
Tom KnowltonWeb developerAuthor Commented:
This looks good....

One quick questin on CR  (carriage return)   versus  LF  (line feed)

What does each one do?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.