TextFieldParser.LineNumber 属性

更新:2007 年 11 月

返回当前行号,或如果流中不再有可用的字符,则返回 -1。

' Usage
Dim value As Long = TextFieldParserObject.LineNumber
' Declaration
Public ReadOnly Property LineNumber As Long

返回值

Integer.

备注

这是一个高级成员;除非单击了“全部”选项卡,否则它不显示在 IntelliSense 中。

在确定行号时不会忽略空行和注释。

示例

本示例在文本文件中搜索名称“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

要求

命名空间:Microsoft.VisualBasic.FileIO

类:TextFieldParser

**程序集:**Visual Basic 运行时库(位于 Microsoft.VisualBasic.dll 中)

权限

不需要任何权限。

请参见

参考

TextFieldParser 对象

TextFieldParser.LineNumber