substrCount static method
Counts non-overlapping occurrences of needle in haystack.
Implementation
static int substrCount(String haystack, String needle) {
if (needle.isEmpty) return 0;
var count = 0;
var start = 0;
while (true) {
final i = haystack.indexOf(needle, start);
if (i == -1) break;
count++;
start = i + needle.length;
}
return count;
}