search for a string in a file

shah123's Avatar
Contributor
How to search for a string in a file. As string might be somewhere in the middle of text file.
Code:
Console.WriteLine("Input a string ");
String data = Console.ReadLine();
sr = File.OpenText(@"C:\username.txt");

String st = sr.ReadToEnd();
?????
help please?

thanks
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
use st.Contains
shah123's Avatar
Contributor
Shabbir Brother you are the star. Thanks a million
shah123's Avatar
Contributor
One more question is

"How to find a position of that string in a file"?

Rgds,
shah123's Avatar
Contributor
I got the answer for position thanks anyway