|
-
March 2nd, 2006, 04:56 AM
#1
Search String in a text file
Hi,
Anyone have any idea on how to search a particular string in a text file?
If using StreamReader, can i do that?
I am writting a function to return true,false; if i could find the particular string.
Please advice. Thanks.
e.g, i wan to open sample.txt to look for "nine"? do i need to read line by line?or i have other option? thanks
sample.txt
one,1
two,2
three,3
..............
-
March 2nd, 2006, 04:58 AM
#2
Re: Search String in a text file
ReadToEnd or ReadLine and then string.contains
Regards
Hansjörg
-
March 2nd, 2006, 10:49 AM
#3
Re: Search String in a text file
class TestFileIO
{
static void Main()
{
string fileName = "test.txt"; // a sample file name
// Delete the file if it exists.
if (System.IO.File.Exists(fileName))
{
string s = "";
System.IO.StreamReader sr = System.IO.File.OpenText(fileName)
while ((s = sr.ReadLine()) != null)
{
if(s.contains("Sample text")
MessageBox.show("Message");
}
}
}
}
just like u can get this in MSDN
http://msdn2.microsoft.com/en-us/library/ms228592.aspx
May be it will help you
regards
Ravi
-
March 2nd, 2006, 07:51 PM
#4
Re: Search String in a text file
thank you so much, i would try it out......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|