I use this code to check if a string exist in a text file that I loaded into memory
foreach (Match m in Regex.Matches(haystack, needle))
richTextBox1.Text += "\nFound @ " + m.Index;
The regex returns the positions where a match occurred but I want
to know the line number?
The best solution would be to call a method that gets the line number only if a match occurs.
This way the performance is not much affected if multiple files were checked and the regexp with
\nwill work. Found this method somewhere on stackoverflow: