TextFieldParser.ReadLine Method
Returns the current line as a string and advances the cursor to the next line.
' Usage
Dim value As String = TextFieldParserObject.ReadLine()
' Declaration
Public Function ReadLine() As String
Return Value
String
Exceptions
The following condition may cause an exception to be thrown:
- Target file does not exist (FileNotFoundException).
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.
Example
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.
Requirements
Namespace:Microsoft.VisualBasic.FileIO
Class:TextFieldParser
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Permissions
No permissions are required.
See Also
Concepts
Parsing Text Files with the TextFieldParser Object