ReadFields Method


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 TrimWhiteSpace 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(  ) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.ReadFields Method

See Also

Close Method, CommentTokens Property, Delimiters Property, EndOfData Property, ErrorLine Property, ErrorLineNumber Property, FieldWidths Property, HasFieldsEnclosedInQuotes Property, LineNumber Property, PeekChars Method, ReadLine Method, ReadToEnd Method, SetDelimiters Method, SetFieldWidths Method, TextFieldParser Object, TextFieldType Property, TrimWhiteSpace Property




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