count method
Returns the number of occurrences of pattern
in the string.
Implementation
int count(String pattern) {
String s = this;
int i = 0;
int cnt = 0;
while (i < this.length) {
i = s.indexOf(pattern, i);
if (i == -1) {
break;
}
cnt++;
i += pattern.length;
}
return cnt;
}