TextFieldParser.EndOfData Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Devuelve True si no hay líneas no vacías y sin comentario entre la posición actual del cursor y el final del archivo.
public:
property bool EndOfData { bool get(); };
public bool EndOfData { get; }
member this.EndOfData : bool
Public ReadOnly Property EndOfData As Boolean
Valor de propiedad
True si no hay más datos que leer; de lo contrario, False.
Ejemplos
En este ejemplo se usa la EndofData propiedad para recorrer en bucle todos los campos del archivo con 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
Comentarios
Esta propiedad se puede usar al leer desde archivos para determinar el final de los datos que se leen.
En la tabla siguiente se enumeran ejemplos de tareas que implican la EndOfData propiedad .
| En | Vea |
|---|---|
| Lectura desde un archivo delimitado | Procedimiento: Leer archivos de texto delimitado por comas |
| Lectura desde un archivo de ancho fijo | Cómo: Leer desde archivos de texto de ancho fijo |