I have a text file which contains the same string of characters in different lines. I read the file using this code:

Dim readTexte() As String = File.ReadAllLines(OuvrirFichier, Encoding.UTF8)
Dim t As String
For Each t In readTexte
    If t.Contains(TreeView1.SelectedNode.Text) Then
        TextBox2.Text = Trim(t.Substring(0, 18))
        TextBox1.Text = Trim(t.Substring(18, 90))
        TextBox4.Text = Trim(t.Substring(107, 120))
    End If

However, I have a problem because when cutting and reading these strings. The code is not able to choose the right line to match the TreeView node, because it identifies several equally perfect strings.

For example, the first line contains 3 substrings (fixed width fields):

Saint, Augustine, and Doctor of the Church.

The second line contains three sub-strings as well, slightly different:

Saint, Monica, and mother of Saint Augustine

When I want to read, my code gives me two Augustines, and mixes Augustine and Monique! The TextBox2 contains the string contained in the treeview.

How can I fix this?

enter image description here

enter image description here

Anonymous Asked question May 14, 2021