count method
- String subString = ""
Counts the occurrences of a substring within a string.
This function searches through the provided String for instances
of the subString
and returns the total number of occurrences found.
Parameters:
subString
- The substring to count within the String.
Returns the number of times subString
appears in String.
Implementation
int count([String subString = ""]) {
if (subString.isEmpty) {
return length;
}
return subString.allMatches(this).length;
}