occurrencesOf method
Counts non-overlapping occurrences of substring.
Returns 0 when substring is empty.
Example:
'banana'.occurrencesOf('a'); // 3
'banana'.occurrencesOf('ana'); // 1
Implementation
int occurrencesOf(String substring) {
if (substring.isEmpty) return 0;
return substring.allMatches(this).length;
}