
604
|
Chapter 13: The ‘My’ Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
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... ...