How to search for a string in a file. As string might be somewhere in the middle of text file. :!:

Console.WriteLine("Input a string ");
String data = Console.ReadLine();
sr = File.OpenText(@"C:\username.txt");

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

help please?

thanks

Recommended Answers

All 2 Replies

solution was st.contains it worked. Thanks anyway

I would have used something like int pos = st.IndexOf(data);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.