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. Advertisements

  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
     
    S. Justin Gengo, Sep 5, 2003
    #2
    1. Advertisements

  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, Sep 6, 2003
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.