keyword searching in a file..Filestream

M

Maheshkumar.R

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.
 
C

cody

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)
{
//...
}
}
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top