-5

I need your help,is there a ready method which gives you the repetition of word in a string in c#?

Mo Haidar
  • 3,748
  • 6
  • 37
  • 76
  • 1
    possible duplicate of [Number of occurrences of a character in a string](http://stackoverflow.com/questions/10391481/number-of-occurrences-of-a-character-in-a-string) – Abdul Ahmad May 02 '15 at 17:14
  • Is that what the question is asking? I understood is as "is there a method which repeats a word". – EyasSH May 02 '15 at 17:16
  • do a simple google search @Mohammad come on now there are so many examples of this on the internet for example http://www.dotnetperls.com/string-occurrence – MethodMan May 02 '15 at 17:31
  • Obviously __not a duplicate__ OP is not asking about characters or strings but about word.. – TaW May 02 '15 at 17:35

1 Answers1

6

A simple regex will do it:

string str = "abcabcabcabcabc"; // 5 times
int cnt = Regex.Matches(str ,"abc").Count; // 5
Amir Popovich
  • 29,350
  • 9
  • 53
  • 99