count method

int count(
  1. String value, [
  2. int start = 0,
  3. int? end
])

Return the number of times a specified value appears in the string.

The default value of start is 0 if the optional arguments start is not assigned. The default value of end is the end of the string if the optional arguments end is null.

print('this'.count('t')); // 1
print('hello'.count('l')); // 2
print('hello'.count('l',0,2)); // 2

Implementation

int count(String value, [int start = 0, int? end]) =>
    value.allMatches(substring(start, end)).length;