472,141 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

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 3352
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.