TextFieldParser.ReadLine 方法

定義

將目前的行以字串傳回,並將游標前進至下一行。

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

傳回

取自檔案或資料流的目前行。

範例

這個範例會讀取檔案 ParserText.txt ,並將它 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

如果 Testfile.txt 不存在,則由 WriteAllText 方法建立。

此範例會將欄位寫入為單一字串;若要讓每一 VbCrLf 行顯示在目的地檔案中自己的行,應該在每個行的結尾附加字元。

備註

方法 ReadLine 不會執行剖析;分隔字段內的行尾字元會解譯為行的實際結尾。

Nothing 如果到達檔案的結尾,則會傳回 。

適用於

另請參閱