I have a string, so how could I check how many times a specific substring is found in the string?
For example,
String1 = "The fox and the hound"
, and I want to know how many times the word "the" appeared.
The idea I had was since "the" has length three, I could check every set of three characters in the string, but I am hoping there is a more efficient way.
indexOf(String)andindexOf(String, int)in API doc