count method

int count(
  1. num substring
)

Get count of a substring in the number. Returns the count of substring in the number.

Implementation

int count(num substring) {
  var count = 0;
  var index = 0;
  while (true) {
    index = toString().indexOf(substring.toString(), index);
    if (index == -1) break;
    count++;
    index++;
  }
  return count;
}