TextFieldParser.FieldWidths 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示正在分析的文本文件中每一列的宽度。
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()
	属性值
一个整数数组,它包含正在分析的文本文件中每一列的宽度。
例外
除数组最后一个条目外的任意位置中的宽度值小于或等于零。
示例
此示例读取文件 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
	注解
仅当 属性设置为 FieldType.FixedWidth时,TextFieldType此属性才有意义。 如果数组中的最后一个条目小于或等于零,则假定该字段的宽度可变。
方法 SetFieldWidths 还可用于设置字段宽度。
下表列出了涉及 FieldWidths 属性的任务的示例。
| 功能 | 查看 | 
|---|---|
| 从固定宽度的文本文件读取 | 如何:读取固定宽度的文本文件 |