TextFieldParser.ReadLine 方法

定義

以字串回傳當前行,並將游標移至下一行。

public:
 System::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 當檔案結束時會回傳。

適用於

另請參閱