ReadToEnd Method


ReadToEnd Method

Location

TextFieldParser.ReadToEnd

Syntax

     Dim fileParser As FileIO.TextFieldParser     ' ...later...     Dim result As String = fileParser.ReadToEnd(  ) 

Description

The ReadToEnd method reads and returns the remaining text in a file being parsed with the TextFieldParser object, starting from the current file position. The text returned is not parsed into distinct fields and may include blank lines and comment lines. If the file position is already at the end of file, this method returns an empty string.

This method advances the current file position to the end of the file and sets the parser's LineNumber property to -1.

Usage at a Glance

You must close the TextFieldParser object when finished with it. Use the object's Close method or create the object instance with the Using keyword. See the TextFieldParser Object entry in this chapter for an example.

Example

This code opens a tab-delimited file for scanning but looks for non-delimited data near the end of the file.

     Dim oneLine(  ) As String     Dim commentary As String     Dim inputFile As FileIO.TextFieldParser = _        My.Computer.FileSystem.OpenTextFieldParser( _        "c:\temp\data.txt", vbTab)     Do While Not inputFile.EndOfData        ' ----- Check for the start of the commentary.        If (inputFile.PeekChars(9) = "COMMENTS:") Then           ' ----- Skip the first line.           commentary = inputFile.ReadLine(  )           commentary = inputFile.ReadToEnd(  )        Else           ' ----- OK to process this line.           oneLine = inputFile.ReadFields(  )           ' ----- Process data here...        End If     Loop     inputFile.Close(  ) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.ReadToEnd Method

See Also

Close Method, CommentTokens Property, EndOfData Property, LineNumber Property, PeekChars Method, ReadFields Method, ReadLine Method, TextFieldParser Object




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net