TextFieldParser.EndOfData Property

Definition

Returns True if there are no non-blank, non-comment lines between the current cursor position and the end of the file.

public:
 property bool EndOfData { bool get(); };
public bool EndOfData { get; }
member this.EndOfData : bool
Public ReadOnly Property EndOfData As Boolean

Property Value

True if there is no more data to read; otherwise, False.

Examples

This example uses the EndofData property to loop through all the fields in the file with the TextFieldReader, FileReader.

Dim StdFormat As Integer() = {5, 10, 11, -1}
Dim ErrorFormat As Integer() = {5, 5, -1}
Using FileReader As New  Microsoft.VisualBasic.FileIO.
    TextFieldParser("C:\testfile.txt")

    FileReader.TextFieldType = FileIO.FieldType.FixedWidth
    FileReader.FieldWidths = StdFormat
    Dim CurrentRow As String()
    While Not FileReader.EndOfData
        Try
            Dim RowType As String = FileReader.PeekChars(3)
            If String.Compare(RowType, "Err") = 0 Then
                ' If this line describes an error, the format of the row will be different.
                FileReader.SetFieldWidths(ErrorFormat)
                CurrentRow = FileReader.ReadFields
                FileReader.SetFieldWidths(StdFormat)
            Else
                ' Otherwise parse the fields normally
                CurrentRow = FileReader.ReadFields
                For Each newString As String In CurrentRow
                    My.Computer.FileSystem.WriteAllText("newFile.txt", newString, True)
                Next
            End If
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            MsgBox("Line " & ex.Message & " is invalid.  Skipping")
        End Try
    End While
End Using

Remarks

This property can be used when reading from files to determine the end of the data being read.

The following table lists examples of tasks involving the EndOfData property.

To See
Read from a delimited file How to: Read From Comma-Delimited Text Files
Read from a fixed-width file How to: Read From Fixed-width Text Files

Applies to

See also