Given I have the following information:
string Sentence = "The dog jumped over the cat and the cat jumped above the mouse."
string startword = "jumped"
string endword = "the"
My requirement is how to program in C# to count the number of occurrences that the Sentence contains the starting of the startword
until matching the second endword
.
The above example should return 2 because The dog [jumped] ... [the] cat and ...cat [jumped] .. [the] mouse.
One of my ideas of to do string.Split the Sentence into string of words and looping through the words and compare with startword
. If startword
matched, then compare the next word to the endword
until found or end of Sentence. If the startword
and endword
have been found, increase the counter, and continue searching for startword
and endword
until end of sentence.
Any other suggestion or code sample will be appreciated.