countOccurrences method

int countOccurrences(
  1. String match, {
  2. bool caseSensitive = true,
})

Counts occurrences of a character in a string.

  • Parameters:
    • match: The character to count.
    • caseSensitive: Whether the match is case-sensitive. Default is true.
  • Returns: The count of the character.

Implementation

int countOccurrences(String match, {bool caseSensitive = true}) {
  var count = 0;
  for (final char in characters) {
    if (caseSensitive ? char == match : char.equalsToIgnoreCase(match)) {
      count++;
    }
  }
  return count;
}