'Is there a way to import text file to datagridview in vb.net

Good day, i am importing text file to datagridview and i want to have the output like this

LOT ADDRESS | NAME | METER NUMBER

0123RR ROAD 6 | DOE, JOHN | 123ABC456789

text file looks like this

0123RR ROAD 6 DOE, JOHN 123ABC456789

the character count from address to name is 25 and 10 from name to meter number.

my code looks like this

    Dim lines() As String
    Dim vals() As String
    OpenFileDialog1.Filter = "TEXT FILE | *.txt |ALL FILES |*.*"
    If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
        lines = File.ReadAllLines(OpenFileDialog1.FileName)
        For i As Integer = 12 To lines.Length - 1 Step +1

            'Dim newlines As String = lines(i).Substring(25, 20)

            vals = lines(i).ToString().Split(" "c, StringSplitOptions.RemoveEmptyEntries)


            Dim row(vals.Length - 1) As String


            For j As Integer = 0 To vals.Length - 1 Step 2

                row(j) = vals(j).Trim()


            Next j
            dt.Rows.Add(row)


        Next i
    End If

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source