TextFieldParser.EndOfData 屬性
更新:2007 年 11 月
如果目前的游標位置和檔案結尾之間沒有非空白行和非註解行,會傳回 True。
' Usage Dim value As Boolean = TextFieldParserObject.EndOfData ' Declaration Public ReadOnly Property EndOfData As Boolean
傳回值
Boolean.
備註
讀取檔案時,這個屬性可用於判斷是否已讀到資料結尾。
工作
下表列出包含 EndOfData 屬性的工作範例。
若要 |
請參閱 |
---|---|
從有分隔符號的檔案讀取。 |
|
從固定寬度的檔案讀取 |
範例
這個範例會將 EndofData 屬性與 TextFieldReaderFileReader 搭配使用,在檔案的所有欄位中執行迴圈。
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
需求
命名空間 (Namespace)︰Microsoft.VisualBasic.FileIO
組件:Visual Basic 執行階段程式庫 (在 Microsoft.VisualBasic.dll 中)
使用權限
下列使用權限是必要的:
使用權限 |
描述 |
---|---|
控制存取檔案和資料夾的功能。關聯的列舉型別:Unrestricted。 |
|
描述套用至程式碼的一組安全性權限。關聯的列舉型別:ControlEvidence。 |