This documentation is archived and is not being maintained.

TextFieldParser.ReadLine Method

Returns the current line as a string and advances the cursor to the next line.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public string ReadLine()

Return Value

Type: System.String

For more detailed information, see the Visual Basic topic TextFieldParser.ReadLine Method.

The ReadLine method performs no parsing; an end-of-line character within a delimited field is interpreted as the actual end of the line.

Nothing is returned if the end of the file is reached.

This example reads through the file ParserText.txt and writes it to Testfile.txt.

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\ParserText.txt")
    MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
    MyReader.Delimiters = New String() {","}
    Dim currentRow As String 
    While Not MyReader.EndOfData
            currentRow = MyReader.ReadLine()
            My.Computer.FileSystem.WriteAllText _
           ("C://testfile.txt", currentRow, True)
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            MsgBox("Line " & ex.Message & " is invalid.  Skipping")
        End Try 
    End While 
End Using

If Testfile.txt does not exist, it is created by the WriteAllText method.

This example writes the fields as a single string; to have each line display on its own line in the destination file, a VbCrLf character should be appended at the end of each line.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0