charCount method
Finds a specific's character occurrence in the String
.
Example
String foo = 'foo';
int occ = foo.charCount('o'); // returns 2
Implementation
int charCount(String char) {
if (this.isBlank) {
return 0;
}
return this!.split('').fold<int>(
0, (previousValue, ch) => previousValue + (ch == char ? 1 : 0));
}