countChars static method
Counts how offen the given char
apears in the given string s
.
The value caseSensitive
controlls whether it should only look for the given char
or also the equivalent lower/upper case version.
Example: Hello and char l => 2
Implementation
static int countChars(String s, String char, {bool caseSensitive = true}) {
var count = 0;
s.codeUnits.toList().forEach((i) {
if (caseSensitive) {
if (i == char.runes.first) {
count++;
}
} else {
if (i == char.toLowerCase().runes.first ||
i == char.toUpperCase().runes.first) {
count++;
}
}
});
return count;
}