string filename = @"D:\sample.txt";
FileStream fs = new FileStream(filename, FileMode.Open);
StreamReader sr = new StreamReader(fs);
do
{
content = sr.ReadLine();
if (Regex.IsMatch(content, searchstr, RegexOptions.IgnoreCase))
{
while ((i = content.IndexOf(searchstr, i)) >=0)
{
count = count + 1;
i++;
}
i = 0;
}
} while (!sr.EndOfStream == true);
textBox1.Text = Convert.ToString(count);
Count will give you how many occurence of word in a text file.
Rmohankumar, if this helps please login to Mark As Answer. | Alert Moderator