I am trying to use an OpenFileDialog
to read all text / lines from a file(it doesn't matter what kind of file), and extract only C# Keywords(I already have the keywords typed into a string
) -But, I can't seem to figure out how to extract ALL occurrences. I don't want to count them, like count++
, I want to display the occurrences in a RichTextBox
This is the code that only gets the first occurrence:
string keywords = @"\b(default|delegate|do|else|event|explicit|extern|false|finally|fixed|for|foreach|goto|if|implicit|in|interface|internal|is|lock|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sealed|sizeof|stackalloc|switch|this|throw|true|try|typeof|unchecked|unsafe|using|virtual|volatile|while)\b";
MatchCollection matches = Regex.Matches(File.ReadAllText(ofdd.FileName), keywords);
foreach (Match match in matches)
{
richTextBox1.Text = (match.Groups[1].Value);
}
-I know I forgot keywords like abstract
, etc.
That code only performs part of the job :( I need it to display ALL occurrences of the keywords
string
Any idea how to display ALL occurrences?