How to check for EOF (End of file) when using StreamReader to parse text file

Discussion in 'ASP .Net' started by Sacha Korell, Sep 5, 2003.

  1. Sacha Korell

    Sacha Korell Guest

    How would I check for an end of file when parsing a text file using the
    StreamReader object?

    I would like to do something like this:

    '********************************
    Dim objStreamReader As StreamReader
    Dim strReqLine As String

    objStreamReader = File.OpenText("data.txt")

    While NOT objStreamReader.EOF

    strReqLine = objStreamReader.ReadLine

    '* Code to parse the line for data

    End While
    '********************************

    Except the StreamReader object doesn't seem to have an EOF property. Are
    there any work-arounds?

    Thanks,

    Sacha
    Sacha Korell, Sep 5, 2003
    #1
    1. Advertising

  2. Sacha,

    Just use:

    While StreamReader.Read

    End While

    It will stop when it hits EOF.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Sacha Korell" <> wrote in message
    news:O$ppRs%...
    > How would I check for an end of file when parsing a text file using the
    > StreamReader object?
    >
    > I would like to do something like this:
    >
    > '********************************
    > Dim objStreamReader As StreamReader
    > Dim strReqLine As String
    >
    > objStreamReader = File.OpenText("data.txt")
    >
    > While NOT objStreamReader.EOF
    >
    > strReqLine = objStreamReader.ReadLine
    >
    > '* Code to parse the line for data
    >
    > End While
    > '********************************
    >
    > Except the StreamReader object doesn't seem to have an EOF property. Are
    > there any work-arounds?
    >
    > Thanks,
    >
    > Sacha
    >
    >
    S. Justin Gengo, Sep 5, 2003
    #2
    1. Advertising

  3. Sacha,

    strReqLine = objStreamReader.ReadLine()
    While Not strReqLine Is Nothing
    '* Code to parse the line for data
    strReqLine = objStreamReader.ReadLine()
    End While



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/
    Please reply only to the newsgroup.
    Mattias Sjögren, Sep 6, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. .Net Sports
    Replies:
    11
    Views:
    1,417
    .Net Sports
    Jan 17, 2006
  2. =?Utf-8?B?S2V2aW4gSw==?=
    Replies:
    2
    Views:
    2,875
    =?Utf-8?B?S2V2aW4gSw==?=
    Apr 6, 2006
  3. damezumari
    Replies:
    2
    Views:
    491
    damezumari
    Apr 27, 2006
  4. Kobu
    Replies:
    10
    Views:
    612
    Keith Thompson
    Mar 4, 2005
  5. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    680
    James Kanze
    Jun 15, 2007
Loading...

Share This Page