SetDelimiters Method


SetDelimiters Method

Location

TextFieldParser.SetDelimiters

Syntax

     Dim fileParser As FileIO.TextFieldParser     ' ...later... fileParser.SetDelimiters(setOfDelimiters) 


setOfDelimiters (required; String array)

An array of the character or multicharacter values that identify the delimiters used to separate data fields in each input line of a delimited text file being parsed by a TextFieldParser object. End-of-line characters may not be used as field delimiters.

Description

The SetDelimiters method sets the field delimiters used in delimited text file parsing. This method also sets the TextFieldParser object's TextFieldType property to Microsoft.VisualBasic.FileIO.FieldType.Delimited. Although you can define more than one delimiter, most input files will use a single field delimiter, such as a comma or a tab character.

You can use the TextFieldParser object's Delimiters property to set the delimiters as well, but that property does not alter the TextFieldType property.

Usage at a Glance

  • The SetDelimiters method is only useful with delimited input files, not fixed-width files.

  • An exception is thrown if you attempt to use line-termination characters, zero-length strings, or Nothing as field delimiters.

  • If the file being parsed only uses a single delimiter, you can pass a standard string with that delimiter to the SetDelimiters method.

  • 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

The following example uses the SetDelimiters method to indicate the comma character as the field delimiter.

     Dim scanInput As Microsoft.VisualBasic.FileIO.TextFieldParser     ' ...later...     scanInput.SetDelimiters(New String(  ) {","}) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.SetDelimiters Method

See Also

CommentTokens Property, Delimiters Property, FieldWidths Property, HasFieldsEnclosedInQuotes Property, ReadFields 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