Documentation

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

import "strings"

strings.countStr(v: "Hello mellow fellow", substr: "ello")

// 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:

strings.coutnStr(v: "ooooo", substr: "oo")

// Returns 2 -- (oo)(oo)o

Examples

Count instances of a substring within a string
import "strings"

data
  |> map(fn: (r) => ({
      r with
      _value: strings.countStr(v: r.message, substr: "uh")
    })
  )

New! Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: