ReadLine Method


ReadLine Method

Location

TextFieldParser.ReadLine

Syntax

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

Description

The ReadLine method reads and returns the current line from a file being parsed with the TextFieldParser object. The returned line is not parsed into distinct fields. If the file position is already at the end of the file, this method returns an empty string.

This method advances the current file position to the start of the next line.

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 performs a different type of processing on lines marked by a special preamble.

     Dim oneLine As String     Dim fieldSet(  ) As String     Dim inputFile As FileIO.TextFieldParser = _        My.Computer.FileSystem.OpenTextFieldParser( _        "c:\temp\data.txt", vbTab)     Do While Not inputFile.EndOfData        ' ----- Check for the special processing flag.        If (inputFile.PeekChars(5) = "SPEC:") Then           ' ----- Do special processing of this line.           oneLine = inputFile.ReadLine(  )           ' ----- Process data here...        Else           ' ----- OK to process this line normally.           fieldSet = inputFile.ReadFields(  )           ' ----- Process data here...        End If     Loop     inputFile.Close(  ) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.ReadLine Method

See Also

Close Method, CommentTokens Property, EndOfData Property, LineNumber Property, PeekChars Method, ReadFields Method, ReadToEnd 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