strings.countStr() function

The strings.countStr() function counts the number of non-overlapping instances of a substring appears in a string.

*Output data type: Integer*

  1. import "strings"
  2. strings.countStr(v: "Hello mellow fellow", substr: "ello")
  3. // returns 3

Parameters

v

The string value to search.

*Data type: String*

substr

The substring to count.

*Data type: String*

The function counts only non-overlapping instances of substr. For example:

  1. strings.coutnStr(v: "ooooo", substr: "oo")
  2. // Returns 2 -- (oo)(oo)o

Examples

Count instances of a substring within a string
  1. import "strings"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. _value: strings.countStr(v: r.message, substr: "uh")
  6. })
  7. )