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 中顯示。

在決定行號時,空白行和註解不會被忽略。

適用於

另請參閱