4 Replies - 223 Views - Last Post: 08 February 2012 - 03:34 PM Rate Topic: -----

Topic Sponsor:

#1 SilverAstrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 10

small Stream Reader Issue

Posted 02 February 2012 - 02:32 PM

StreamReader reader = new StreamReader(stream);
            string line = "";
            
            //loop through file
            while ((line = reader.ReadLine()) != null)
            {
                
                Regex dateMatcher = new Regex("\\d");

                //if we found a date
                if (dateMatcher.Match(line, 0, 1).Success)
                {
                    //store it
                    time = ParseDate(line);
                }
                    //look for @, take next two lines
                    //if no @ is found before next date, reset time and try again
                Regex statMatcher = new Regex("@");

                //if we found a date
                if (statMatcher.Match(line, 0, 1).Success)
                {
                    //this line right heah is an issue
                    string line2 = reader.ReadLine();
                    LBStatsData res = ParseData(line, line2);
                    res.Date = time;
                    stats.Add(res);
                }
            }


below the comment "this line right heah is an issue" I thought that ReadLine() would read the NEXT line from the stream, but it seems to be getting the current one, can anyone tell me what I'm doing wrong? I need to get that next line right there in the code...

Is This A Good Question/Topic? 0
  • +

Replies To: small Stream Reader Issue

#2 eclipsed4utoo  Icon User is online

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1451
  • View blog
  • Posts: 5,763
  • Joined: 21-March 08

Re: small Stream Reader Issue

Posted 02 February 2012 - 03:22 PM

So you need to get the current line and the next line in the same loop?
Was This Post Helpful? 0
  • +
  • -

#3 Ionut  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 327
  • View blog
  • Posts: 914
  • Joined: 17-July 10

Re: small Stream Reader Issue

Posted 03 February 2012 - 11:14 AM

I would suggest you the next steps:
1. use ReadToEnd to read the entire content of the file
2. Use Split function.
3. Now you have all lines in an array and you can access every line by an index.
Was This Post Helpful? 0
  • +
  • -

#4 SilverAstrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 10

Re: small Stream Reader Issue

Posted 04 February 2012 - 11:44 PM

View Posteclipsed4utoo, on 02 February 2012 - 03:22 PM, said:

So you need to get the current line and the next line in the same loop?


That would be the idea, yes. And I'm not sure I'd want to index all the lines, either. Would you know a way? Thanks =]
Was This Post Helpful? 0
  • +
  • -

#5 SilverAstrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 10

Re: small Stream Reader Issue

Posted 08 February 2012 - 03:34 PM

I got it figured out =] Thanks though!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1