strings.trimSuffix() function

The strings.trimSuffix() function removes a suffix from a string. Strings that do not end with the suffix are returned unchanged.

*Output data type: String*

  1. import "strings"
  2. strings.trimSuffix(v: "123_abc", suffix: "abc")
  3. // returns "123_"

Parameters

v

The string value to trim.

*Data type: String*

suffix

The suffix to remove.

*Data type: String*

Examples

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

Related articles