次の方法で共有


TextFieldParser.EndOfData プロパティ

更新 : 2007 年 11 月

現在のカーソル位置とファイルの末尾との間に、空白行とコメント行しかない場合に True を返します。

' Usage
Dim value As Boolean = TextFieldParserObject.EndOfData
' Declaration
Public ReadOnly Property EndOfData As Boolean

戻り値

Boolean.

解説

このプロパティはファイルの読み取りの際に、データの最後が読み取られたかどうかを判断するために使用します。

処理手順

EndOfData プロパティに関連するタスクの例を次の表に示します。

目的

参照項目

区切り記号入りファイルからの読み取り

方法 : Visual Basic でコンマ区切りのテキスト ファイルを読み取る

固定幅のファイルからの読み取り

方法 : Visual Basic で固定幅のテキスト ファイルを読み取る

使用例

次の例は 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

必要条件

名前空間 : Microsoft.VisualBasic.FileIO

クラス : TextFieldParser

アセンブリ : Microsoft Visual Basic ランタイム (Microsoft.VisualBasic.dll 内)

アクセス許可

必要なアクセス許可を次に示します。

アクセス許可

説明

FileIOPermission

ファイルとフォルダへのアクセス許可を制御します。関連する列挙値 : Unrestricted

SecurityPermission

コードに適用されたセキュリティ アクセス許可のセットを記述します。関連する列挙値 : ControlEvidence

詳細については、「コード アクセス セキュリティ」および「アクセス許可の要求」を参照してください。

参照

参照

TextFieldParser オブジェクト

TextFieldParser.EndOfData