944,123 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 20270
  • C# RSS
Apr 10th, 2007
0

How to search for a string in a file

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
shsh_shah is offline Offline
29 posts
since Mar 2007
Apr 10th, 2007
0

Re: How to search for a string in a file

solution was st.contains it worked. Thanks anyway
Reputation Points: 10
Solved Threads: 0
Light Poster
shsh_shah is offline Offline
29 posts
since Mar 2007
Apr 10th, 2007
0

Re: How to search for a string in a file

I would have used something like

int pos = st.IndexOf(data);
Reputation Points: 407
Solved Threads: 36
Posting Virtuoso
Lardmeister is offline Offline
1,701 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Exprot to Excel in ASP.NET using C#
Next Thread in C# Forum Timeline: Ignore case strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC