TextFieldParser.LineNumber 屬性

定義

傳回目前的行號,如果資料流中已沒有可用的字元,則會傳回 -1。

public:
 property long LineNumber { long get(); };
public long LineNumber { get; }
member this.LineNumber : int64
Public ReadOnly Property LineNumber As Long

屬性值

目前行號。

範例

本範例會在文本檔中搜尋名稱 「Jones」,並報告其發生) 行 (。

Using FileReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\ParserText.txt")
    FileReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
    FileReader.Delimiters = New String() {","}
    Dim currentRow As String()
    While Not FileReader.EndOfData
        Try
            currentRow = FileReader.ReadFields()
            Dim currentField As String
            For Each currentField In currentRow
                If currentField = "Jones" Then
                    MsgBox("The name Jones occurs on line " & 
                    FileReader.LineNumber)
                End If
            Next
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            MsgBox("Line " & ex.Message & 
           "is not valid and will be skipped.")
        End Try
    End While
End Using

備註

這是進階成員;除非您按兩下 [ 所有 ] 索引標籤,否則不會顯示在IntelliSense 中。

決定行號時,不會忽略空白行和批注。

適用於

另請參閱