TextFieldParser.ReadLine Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the current line as a string and advances the cursor to the next line.
public:
System::String ^ ReadLine();
public string? ReadLine ();
public string ReadLine ();
member this.ReadLine : unit -> string
Public Function ReadLine () As String
The current line from the file or stream.
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.
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.
Product | Versies |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET-feedback
.NET is een open source project. Selecteer een koppeling om feedback te geven: