TextFieldParser.EndOfData Propriété

Définition

Retourne True s’il n’existe aucune ligne non vide, sans commentaire entre la position actuelle du curseur et la fin du fichier.

public:
 property bool EndOfData { bool get(); };
public bool EndOfData { get; }
member this.EndOfData : bool
Public ReadOnly Property EndOfData As Boolean

Valeur de propriété

True s’il n’y a plus de données à lire ; sinon, False.

Exemples

Cet exemple utilise la EndofData propriété pour parcourir tous les champs du fichier avec le TextFieldReaderfichier . 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

Remarques

Cette propriété peut être utilisée lors de la lecture de fichiers pour déterminer la fin des données lues.

Le tableau suivant répertorie des exemples de tâches impliquant la EndOfData propriété.

À Consultez
Lecture à partir d’un fichier délimité Comment lire à partir de fichiers texte Comma-Delimited
Lecture à partir d’un fichier à largeur fixe Guide pratique pour lire à partir de fichiers texte à largeur fixe

S’applique à

Voir aussi