TextFieldParser.FieldWidths 속성

정의

구문 분석되는 텍스트 파일에서 각 열의 너비를 나타냅니다.

public:
 property cli::array <int> ^ FieldWidths { cli::array <int> ^ get(); void set(cli::array <int> ^ value); };
public int[]? FieldWidths { get; set; }
public int[] FieldWidths { get; set; }
member this.FieldWidths : int[] with get, set
Public Property FieldWidths As Integer()

속성 값

Int32[]

구문 분석되는 텍스트 파일에 있는 각 열의 너비가 들어 있는 정수 배열입니다.

예외

배열의 마지막 항목을 제외한 위치의 너비 값이 0 이하인 경우

예제

이 예제에서는 너비를 지정하는 파일을 ParserText.txt읽습니다. 첫 번째 열은 너비가 5자이고, 두 번째 열은 10이고, 세 번째 열은 11이고, 네 번째 열은 가변 너비입니다.

Using MyReader As New Microsoft.VisualBasic.FileIO.
    TextFieldParser("C:\ParserText.txt")

    MyReader.TextFieldType = 
        Microsoft.VisualBasic.FileIO.FieldType.FixedWidth
    MyReader.FieldWidths = {5, 10, 11, -1}
    Dim currentRow As String()
    While Not MyReader.EndOfData
        Try
            currentRow = MyReader.ReadFields()
            Dim currentField As String
            For Each currentField In currentRow
                MsgBox(currentField)
            Next
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            MsgBox("Line " & ex.Message & 
            "is not valid and will be skipped.")
        End Try
    End While
End Using

설명

이 속성은 속성이 로 TextFieldType 설정된 경우에만 의미가 있습니다 FieldType.FixedWidth. 배열의 마지막 항목이 0보다 작거나 같으면 필드는 가변 너비로 간주됩니다.

메서드를 SetFieldWidths 사용하여 필드 너비를 설정할 수도 있습니다.

다음 표에서 관련 된 작업의 예제는 FieldWidths 속성입니다.

대상 참조 항목
고정 너비 텍스트 파일에서 읽기 방법: 고정 너비 텍스트 파일에서 읽기

적용 대상

추가 정보