@nevware21/ts-utils
    Preparing search index...

    Function strCount

    • Count the number of non-overlapping occurrences of a substring within the provided value.

      Both value and searchString are converted to strings using asString before searching. If the converted search string is empty, this function returns 0 to avoid an unbounded match count. The value parameter must not be null or undefined, while searchString may be null or undefined and will be stringified (for example, to "null" or "undefined").

      Parameters

      • value: string

        The value to search within. Must not be null or undefined; it is coerced to a string using asString before searching.

      • searchString: string

        The substring to count. It is coerced to a string using asString; if null or undefined, it is stringified (for example, to "null" or "undefined"). If the resulting string is empty, 0 is returned.

      Returns number

      The number of non-overlapping substring occurrences.

      0.14.0

      If value is null or undefined.

      strCount("hello hello", "hello"); // 2
      strCount("aaaa", "aa"); // 2
      strCount("banana", "ana"); // 1
      strCount("abc", ""); // 0
      strCount("null hello null", null as any); // 2 - searchString is coerced to "null"