Documentation

strings.countStr() function

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

Function type signature
(substr: string, v: string) => int
For more information, see Function type signatures.

Parameters

v

(Required) String value to search.

substr

(Required) Substring to count occurences of.

The function counts only non-overlapping instances of substr.

Examples

Count instances of a substring within a string

import "sampledata"
import "strings"

sampledata.string()
    |> map(fn: (r) => ({r with _value: strings.countStr(v: r._value, substr: "p")}))

View example input and ouput


Was this page helpful?

Thank you for your feedback!


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.