Does this meet your needs? string str = "How do I search if a words exist in a string"; MatchCollection mc = Regex.Matches(str, " a "); Console.WriteLine(mc.Count.ToString());
or perhaps... string str = "How do I search if a words exist in a string"; int index = str.IndexOf(" a "); int numWords = 0; while(index != -1) { index = str.IndexOf(" a ", index + 1); numWords++; } Console.WriteLine(numWords.ToString());
V
V ktor
@V ktor
Posts
-
Searching for words in a string