469,356 Members | 2,656 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

keyword searching in a file..Filestream

Hi all,
I'm new bie to windows application..i want to search a key word inside a file..let say, if a file contains text "this is sample program...". If i search "sample" inside a file, it should give the exact matching.

------my code
FileStream fs = new FileStream("C:\\a.txt", FileMode.Open, FileAccess.Read);
StreamReader fs1 = new StreamReader(fs);
String mystring="sample";

while (string == fs1. ____ )
{
Messagbox.show("Yes i got ur string ..");
}
please help me to complete this missing keyword or code to get out of this problem.
------------------
thanks,
Mähésh Kumär. R

Nov 17 '05 #1
1 3016
use ReadLine() to read the file line for line and use string.IndexOf() to search your string within the returned string.

string line;
while ((line =ReadLine())!=null
{
if (line.IndexOf("sample")!=-1)
{
//...
}
}
"Maheshkumar.R" <cy**********@yahoo.com> schrieb im Newsbeitrag news:ed**************@TK2MSFTNGP09.phx.gbl...
Hi all,
I'm new bie to windows application..i want to search a key word inside a file..let say, if a file contains text "this is sample program...". If i search "sample" inside a file, it should give the exact matching.

------my code
FileStream fs = new FileStream("C:\\a.txt", FileMode.Open, FileAccess.Read);
StreamReader fs1 = new StreamReader(fs);
String mystring="sample";

while (string == fs1. ____ )
{
Messagbox.show("Yes i got ur string ..");
}
please help me to complete this missing keyword or code to get out of this problem.
------------------
thanks,
Mähésh Kumär. R

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mehul Patel | last post: by
2 posts views Thread by Senthil | last post: by
12 posts views Thread by Brian Henry | last post: by
17 posts views Thread by Peter Duniho | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.