strings.trimPrefix() function

The strings.trimPrefix() function removes a prefix from a string. Strings that do not start with the prefix are returned unchanged.

*Output data type: String*

  1. import "strings"
  2. strings.trimPrefix(v: "123_abc", prefix: "123")
  3. // returns "_abc"

Parameters

v

The string value to trim.

*Data type: String*

prefix

The prefix to remove.

*Data type: String*

Examples

Remove a prefix from all values in a column
  1. import "strings"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. sensorID: strings.trimPrefix(v: r.sensorId, prefix: "s12_")
  6. })
  7. )

Related articles