Angel Us Angel Us - 1 month ago 7
Vb.net Question

search for number in txt.file and get all results

I have a text file containing a 30,000-line
I want to search for two numbers designated in the text file ...
And the results I get is a whole line .....
This is an example of the way the search and display the results ...
Please help me, because I need it very badly

An example of the text to be searched inside

enter image description here

Desired results

enter image description here

Answer

Something like the below could work. What it does is, loops through your file line at a time and uses an IF statement to test if it meets the requirements. Then once you find the line, return it or do what you want with it and then exit the for loop if found.

For Each line As String In File.ReadLines("file.txt")
    If line.Contains("Here put the first number") AndAlso line.Contains("Here put the second number")
          'you found the line, now return the line
           Exit For 'Once you found the line exit the loop, as it will continue reading the file
    End If
Next

Also this information could have found by googling how to read in a file. File.ReadLines This link can help you understand whats happening.

Comments