TextFieldParser.ReadLine TextFieldParser.ReadLine TextFieldParser.ReadLine TextFieldParser.ReadLine Method

Definition

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

public:
 System::String ^ ReadLine();
public string ReadLine ();
member this.ReadLine : unit -> string
Public Function ReadLine () As String

Returns

The current line from the file or stream.

Examples

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
        Try
            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.

Remarks

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.

Applies to

See also