Here is a simple example to get you started, it prints the line numbers and the text of the lines:
this.FindWords("test.txt", "private");
private void FindWords(string fileName, string searchString)
{
string line;
int count = 1;
using (TextReader reader = File.OpenText(fileName))
{
while ((line = reader.ReadLine()) != null)
{
if (line.Contains(searchString))
{
Console.WriteLine(count + " " + line);
}
count++;
}
}
}
It would be a good idea to improve this with
Regex search expressions, here is a nice Regex example (don't fear it aims to take away the complexity of Regex):
Converting Wildcards to Regexes[
^]
Another idea would be to use the Fast Colored TextBox, as the standard RichTextBox is really a hassle to use:
Fast Colored TextBox for Syntax Highlighting[
^]