keyword searching in a file..Filestream

  • Thread starter Thread starter Maheshkumar.R
  • Start date Start date
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.
 
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.
 
Back
Top