countOccurences method

int countOccurences(
  1. String find
)

Counts the occurences of find in a string

Implementation

int countOccurences(String find) {
  int count = 0;
  int matchIndex = 0;
  if (this.isEmpty || find.isEmpty) {
    return count;
  }
  do {
    matchIndex = this.indexOf(find, matchIndex);
    if (matchIndex != -1) {
      count++;
      matchIndex += find.length;
    }
  } while (matchIndex != -1);
  return count;
}