Search for string in text file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to search for a string in a text file. I suppose StreamReader would
work. But can someone help me on this?
Thanks
 
VB User said:
I need to search for a string in a text file. I suppose StreamReader would
work. But can someone help me on this?

Yes - use StreamReader. Open the file, read the text from it and do the
search on the string. If you don't mind the search being line by line
(i.e. you're not searching for something which could contain line
breaks) you could read the file line by line so you never need to have
the whole file in memory. Use String.IndexOf to test whether or not the
string you're interested in is in another string.
 
Back
Top