I'm working with a text file that looks like this:
----------------------------------------
Récord por alumno
Version: 4
'Tue Feb 06 14:09:12 2018'
----------------------------------------
5%Carrera 100 mts
Subprueba: 50 mts
Measured: 15.2
High Limit: 12.00
Low Limit: 18.00
Time in Seconds
Status: 2nd place
----------------------------------------
4%Lagartijas 20 en 25 seg
Subprueba: 10 en 10 seg
Measured: 24
High Limit: 25
Time in Seconds
Status: 2nd place
----------------------------------------
Alumno : Cervantes,Gonzalo
----------------------------------------
5%Carrera 100 mts
Subprueba: 50 mts
Measured: 14.7
High Limit: 12.00
Low Limit: 18.00
Time in Seconds
Status: 1nd place
----------------------------------------
4%Lagartijas 20 en 25 seg
Subprueba: 10 en 10 seg
Measured: 25
High Limit: 25
Time in Seconds
Status: 1nd place
----------------------------------------
Alumno : Hernandez,Pedro
----------------------------------------
5%Carrera 100 mts
Subprueba: 50 mts
Measured: 15.2
High Limit: 12.00
Low Limit: 18.00
Time in Seconds
Status: 2nd place
----------------------------------------
3%Lagartijas 22 en 25 seg
Subprueba: 10 en 10 seg
Measured: 24
High Limit: 25
Time in Seconds
Status: 2nd place
----------------------------------------
Alumno : Ramirez,José
and this is the code I'm working on:
Private Sub Btn_ejecutar_Click(sender As Object, e As EventArgs) Handles Btn_ejecutar.Click
Dim fName As String = ""
OpenFileDialog1.InitialDirectory = "C:\Test\"
OpenFileDialog1.Filter = "Text files(*.Txt)|*.txt"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
fName = OpenFileDialog1.FileName
End If
TextBox1.Text = fName
Dim TextLine As String = ""
If System.IO.File.Exists(fName) = True Then
Dim objReader As New System.IO.StreamReader(TextBox1.Text, Encoding.ASCII)
Dim index As Integer = 0
Do While objReader.Peek() <> -1
If index > 0 Then
TextLine = objReader.ReadLine()
Dim arr() As String = {TextLine}
Dim value1 As String = Array.Find(arr, Function(x) (x.Contains("2018")))
Dim value2 As String = Array.Find(arr, Function(x) (x.Contains("%")))
Dim value3 As String = Array.Find(arr, Function(x) (x.StartsWith("Measured:")))
Dim value4 As String = Array.Find(arr, Function(x) (x.StartsWith("High Limit:")))
Dim value5 As String = Array.Find(arr, Function(x) (x.StartsWith("Low Limit:")))
Dim value6 As String = Array.Find(arr, Function(x) (x.StartsWith("Alumno : ")))
If (Not String.IsNullOrEmpty(value1) Or Not String.IsNullOrEmpty(value2) Or Not String.IsNullOrEmpty(value3) Or Not String.IsNullOrEmpty(value4) Or Not String.IsNullOrEmpty(value5) Or Not String.IsNullOrEmpty(value6)) Then
Dim allarray() As String = {value1, value2, value3, value4, value5, value6}
dt.LoadDataRow(allarray, True)
End If
Else
TextLine = objReader.ReadLine()
End If
index = index + 1
Loop
DataGridView1.Rows.Clear()
DataGridView1.DataSource = dt
Else
MsgBox("File Does Not Exist")
End If
End Sub
However, when generating the arrays I get blank spaces, making the information appear staggered, I have not been able to sort it into a single line and I am already leaving the matter to go around so many times, I append image of my result against the I would like to read, I appreciate very much the guidance you can give me to solve this problem.