-1

Looking to find a way, via string match, to find multiple occurrences of the same word using the streamreader class and contains method (or some other approach). Below only returns a match on the first occurrence, however if I'm evaluating a string that has "the" 3 times in the string, how can I capture all 3 of those for a count result?

while ((line = file.ReadLine()) != null)    
{
      if (line.Contains(text))
      {
          counter++;
      }
}
Sway55
  • 1
  • 1

1 Answers1

0
Regex.Matches(line, text).Count
Imbar M.
  • 1,074
  • 1
  • 10
  • 19