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*

  1. import "strings"
  2. strings.replace(v: "oink oink oink", t: "oink", u: "moo", i: 2)
  3. // 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
  1. import "strings"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. content: strings.replace(v: r.content, t: "he", u: "her", i: 3)
  6. })
  7. )

Related articles