countChar function Null safety

int countChar(
  1. String string,
  2. String char
)

Counts the occurrences of a char in a string.

Implementation

int countChar(String string, String char) {
  var rc = 0;
  for (var ix = string.length - 1; ix >= 0; ix--) {
    if (string[ix] == char) {
      rc++;
    }
  }
  return rc;
}