Documentation

strings.replace() function

The strings.replace() function replaces the first i non-overlapping instances of a substring with a specified replacement.

Output data type: String

import "strings"

strings.replace(v: "oink oink oink", t: "oink", u: "moo", i: 2)

// returns "moo moo oink"

Parameters

v

The string value to search.

Data type: String

t

The substring value to replace.

Data type: String

u

The replacement for i instances of t.

Data type: String

i

The number of non-overlapping t matches to replace.

Data type: Integer

Examples

Replace a specific number of string matches
import "strings"

data
  |> map(fn: (r) => ({
      r with
      content: strings.replace(v: r.content, t: "he", u: "her", i: 3)
    })
  )

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: