count method

  1. @useResult
int count(
  1. String find
)

Returns the number of non-overlapping occurrences of find in this string.

Example:

'hello'.count('l'); // 2
'aaa'.count('aa'); // 1 (non-overlapping)
'test'.count('x'); // 0
'hello'.count(''); // 0

Implementation

@useResult
int count(String find) {
  if (find.isEmpty) {
    return 0;
  }

  return split(find).length - 1;
}