TextFieldParser.EndOfData 屬性

定義

如果目前的游標位置和檔案結尾之間沒有非空白的非註解行,則會傳回 True

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

屬性值

如果沒有任何資料可供讀取則為 True,否則為 False

範例

此範例會 EndofData 使用 屬性,以 TextFieldReaderFileReader迴圈查看檔案中的所有欄位。

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

備註

從檔案讀取時,可以使用這個屬性來判斷正在讀取的數據結尾。

下表列出涉及 屬性的工作 EndOfData 範例。

收件者 請參閱
從分隔的檔案讀取 作法:從逗號分隔文字檔讀取
從固定寬度檔案讀取 作法:從固定寬度的文字檔讀取

適用於

另請參閱