TextFieldParser.ReadLine 메서드

업데이트: 2007년 11월

현재 줄을 문자열로 반환하고 커서를 다음 줄로 이동합니다.

' Usage
Dim value As String = TextFieldParserObject.ReadLine()
' Declaration
Public Function ReadLine() As String

반환 값

String

예외

다음 조건에서 예외가 throw될 수 있습니다.

설명

ReadLine 메서드는 구문 분석을 수행하지 않으며 구분된 필드의 줄 끝(EOL) 문자는 줄의 실제 끝으로 해석됩니다.

Nothing은 파일 끝에 도달하면 반환됩니다.

예제

다음 예제에서는 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 문자를 추가해야 합니다.

요구 사항

네임스페이스:Microsoft.VisualBasic.FileIO

클래스:TextFieldParser

어셈블리: Visual Basic 런타임 라이브러리(Microsoft.VisualBasic.dll)

권한

사용 권한이 필요하지 않습니다.

참고 항목

개념

TextFieldParser 개체를 사용하여 텍스트 파일 구문 분석

참조

TextFieldParser 개체

TextFieldParser.ReadLine

TextFieldParser.ReadFields 메서드

TextFieldParser.ReadToEnd 메서드