How to search for a string in a file

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 29
Reputation: shsh_shah is an unknown quantity at this point 
Solved Threads: 0
shsh_shah shsh_shah is offline Offline
Light Poster

How to search for a string in a file

 
0
  #1
Apr 10th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 29
Reputation: shsh_shah is an unknown quantity at this point 
Solved Threads: 0
shsh_shah shsh_shah is offline Offline
Light Poster

Re: How to search for a string in a file

 
0
  #2
Apr 10th, 2007
solution was st.contains it worked. Thanks anyway
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,528
Reputation: Lardmeister is an unknown quantity at this point 
Solved Threads: 22
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Posting Virtuoso

Re: How to search for a string in a file

 
0
  #3
Apr 10th, 2007
I would have used something like

int pos = st.IndexOf(data);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC