
ReadFields Method | 603
The ‘My’
Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
ReadFields Method
Location
TextFieldParser.ReadFields
Syntax
Dim fileParser As FileIO.TextFieldParser
' ...later...
Dim result As String( ) = fileParser.ReadFields( )
Description
The ReadFields method is the main processing method of the TextFieldParser object. It
reads all delimited or fixed-width fields in the current record of the input file and
returns those fields as a string array. The fields returned from a delimited input file
may be altered in content through the HasFieldsEnclosedInQuotes and Trim-
WhiteSpace properties. Blank lines and comment lines are always ignored.
After reading the record, the current file position advances to the start of the next
record.
Usage at a Glance
An exception is thrown if the parser is unable to extract the delimited or fixed-width
fields currently configured through the TextFieldParser object. The ErrorLine and
ErrorLineNumber properties will provide details on the errant record.
Example
This code processes a tab-delimited file using the ReadFields method.
Dim oneLine( ) As String
Dim inputFile As FileIO.TextFieldParser = _
My.Computer.FileSystem.OpenTextFieldParser( _
"c:\temp\data.txt", vbTab)
Do While Not inputFile.EndOfData
oneLine = inputFile.ReadFields( )
' ----- Process data here...
Loop
inputFile.Close( ...