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 ,將檔案中所有欄位 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

備註

此特性可用於從檔案讀取資料的終點。

下表列出涉及該 EndOfData 屬性的任務範例。

看!
從分隔檔讀取 如何讀取 Comma-Delimited 文本文件
從固定寬度檔案讀取 如何:從固定寬度文本文件讀取

適用於

另請參閱