TextFieldParser.EndOfData 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
如果 True 当前游标位置与文件的末尾之间没有非空白的非注释行,则返回。
public:
property bool EndOfData { bool get(); };
public bool EndOfData { get; }
member this.EndOfData : bool
Public ReadOnly Property EndOfData As Boolean
属性值
True 如果没有更多要读取的数据,则为否则,为 False.
示例
此示例使用 EndofData 该属性循环访问文件中 TextFieldReader包含的 、 FileReader.
Dim StdFormat As Integer() = {5, 10, 11, -1}
Dim ErrorFormat As Integer() = {5, 5, -1}
Using FileReader As New Microsoft.VisualBasic.FileIO.
TextFieldParser("C:\testfile.txt")
FileReader.TextFieldType = FileIO.FieldType.FixedWidth
FileReader.FieldWidths = StdFormat
Dim CurrentRow As String()
While Not FileReader.EndOfData
Try
Dim RowType As String = FileReader.PeekChars(3)
If String.Compare(RowType, "Err") = 0 Then
' If this line describes an error, the format of the row will be different.
FileReader.SetFieldWidths(ErrorFormat)
CurrentRow = FileReader.ReadFields
FileReader.SetFieldWidths(StdFormat)
Else
' Otherwise parse the fields normally
CurrentRow = FileReader.ReadFields
For Each newString As String In CurrentRow
My.Computer.FileSystem.WriteAllText("newFile.txt", newString, True)
Next
End If
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & " is invalid. Skipping")
End Try
End While
End Using
注解
从文件读取时,可以使用此属性来确定要读取的数据的末尾。
下表列出了涉及 EndOfData 该属性的任务的示例。
| 收件人 | 请参阅 |
|---|---|
| 从带分隔符的文件读取 | 如何:从 Comma-Delimited 文本文件中读取 |
| 从固定宽度文件读取 | 如何:从固定宽度的文本文件中读取 |