c# code snippet to search for a count of particular word from a textbased files.
StreamReader sr = new StreamReader(@"C:\yourfilename.txt"); // open the file
read string text = sr.ReadToEnd();
sr.Close();
string word = "search keyword" // word which we want to search
Regex r = new Regex(@"\b" + word + @"\b", RegexOptions.IgnoreCase);
MatchCollection mc = r.Matches(text);
int i = mc.Count.ToString();
Subscribe to:
Comments (Atom)