PeekChars Method


PeekChars Method

Location

TextFieldParser.PeekChars

Syntax

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


peekLength (required; Integer)

The number of characters to read and return

Description

The PeekChars method returns the specified number of characters from the current position in the input file, but it does not alter the current position. Blank lines are ignored when using this method.

Usage at a Glance

  • This method never returns characters beyond the end of the current line, no matter now many characters were requested.

  • 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 stops early if it detects an artificial end-of-file marker.

     Dim oneLine(  ) As String     Dim inputFile As FileIO.TextFieldParser = _        My.Computer.FileSystem.OpenTextFieldParser( _        "c:\temp\data.txt", vbTab)     Do While Not inputFile.EndOfData        ' ----- Check for the EOF marker.        If (inputFile.PeekChars(3) = "EOF") Then Exit Do        ' ----- OK to process this line.        oneLine = inputFile.ReadFields(  )        ' ----- Process data here...     Loop     inputFile.Close(  ) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.PeekChars Method

See Also

EndOfData Property, LineNumber Property, ReadFields Method, ReadLine 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