Results 1 to 5 of 5

Thread: [2.0] quick question 'bout streamreader

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    [2.0] quick question 'bout streamreader

    how do i read the last line of a document and put it into an array?

    double lastLine = code for reading last line;
    myArray.SetValue(lastLine, 0);

    something like that?.. yea.. quick question. thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] quick question 'bout streamreader

    To read the last line of a file using a StreamReader you must first read every other line because a StreamReader is forward-only. There is no way to know how many lines it contins without reading them. The StreamReader's Peek method returns -1 when there is no data remaining, so you can just read a line into a variable in a loop until Peek returns -1. Then the value in the variable is the last line.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] quick question 'bout streamreader

    thank you so much!!!!!! it works now!!! *rates post*

    Edit: I must go around and spread other rep first? What if jmc is the only one who helps me VBForums, huh?! huh?!!?!

    lol.. sorry jmc =/

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] quick question 'bout streamreader

    I don't do it for the rep. I do it for the money that you send me completely voluntarily.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] quick question 'bout streamreader

    hehe.. right....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width