If the wordToSearch is only one word, you can test each letter in each word of the file.
Say that every word has to have an equal length as the word where you search to and may have 2 chars that are wrong, than maybe this can work?
Dim wordToSearch As String = txtSearch.Text.ToLower
Dim lines() As String = IO.File.ReadAllLines("c:\test.txt")
For x As integer = 0 To lines.length - 1
Dim words() As string = lines(x).split(chr10)
For y As integer = 0 To words.length - 1
If words(y).length = wordToSearch.length Then
Dim counter As integer = 0
For z As integer = 0 To wordToSearch.length - 1
If words(y).substring(z,1) = wordToSearch.substring(z,1) Then
counter += 1
End If
If counter > wordToSearch.length - 2
txtNew.Text += lines(x) + vbNewLine
End If
Next
End If
Next
Next
I know that it will be slower than your code and it also can't have multiple words.
For more than 1 word, you can do it for every word and then count the points of each sentence?
(You can set it in an array and then show in a datagrind.)
I hope that this can help you?
Best regards,
Wim
__________________________________
Last add:
Like you have requested - the implement with an array:
Dim wordsSearch() As String = txtSearch.Text.ToLower.Split(" ")
Dim lines() As String = IO.File.ReadAllLines("c:\test.txt")
Dim PointsArray(lines.Length - 1) As Integer
Dim wordToSearch As String
For count2 As Integer = 0 To PointsArray.Length - 1
PointsArray(count2) = 0
Next
For x As Integer = 0 To lines.Length - 1
Dim words() As String = lines(x).Split(" ")
For a As Integer = 0 To wordsSearch.Length - 1
wordToSearch = wordsSearch(a)
For y As Integer = 0 To words.Length - 1
If 0 <= words(y).Length - wordToSearch.Length And (words(y).Length - wordToSearch.Length) < 2 Then
Dim counter As Integer = 0
For z As Integer = 0 To wordToSearch.Length - 1
If words(y).Substring(z, 1) = wordToSearch.Substring(z, 1) Then
counter += 1
End If
Next
If counter > wordToSearch.Length - 2 Then
PointsArray(x) += 1
End If
End If
Next
Next
Next
Dim ArrayLines(lines.Length - 1) As Integer
For x As Integer = 0 To lines.Length - 1
ArrayLines(x) = x
Next
Dim i As Integer
Dim v As Boolean
Dim j As Integer
Dim temp As Integer
Dim temp2 As Integer
Dim count As Integer = PointsArray.Length - 1
i = 0
v = True
Do While i < count - 1 And v = True
v = False
j = 0
Do While j <= count - i - 1
If PointsArray(j) > PointsArray(j + 1) Then
temp = PointsArray(j)
PointsArray(j) = PointsArray(j + 1)
PointsArray(j + 1) = temp
temp2 = ArrayLines(j)
ArrayLines(j) = ArrayLines(j + 1)
ArrayLines(j + 1) = temp2
v = True
End If
j = j + 1
Loop
i = i + 1
Loop
Dim results As Integer = PointsArray.Length - 6
If results < 0 Then
results = 0
End If
For i = PointsArray.Length - 1 To results Step -1
If PointsArray(i) = 0 Then
Exit For
End If
txtNew.Text += "Line nr. " + ArrayLines(i).ToString + " :" + lines(ArrayLines(i)) + vbNewLine
Next