• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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  !!

Tom Knowlton
Tom Knowlton
1 Solution
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;
Tom KnowltonWeb developerAuthor Commented:
This looks good....

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

What does each one do?

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now