docs-v2/content/v2.0/reference/flux/functions/strings/trimsuffix.md

1.1 KiB

title description menu weight related
strings.trimSuffix() function The `strings.trimSuffix()` function removes a suffix from a string. Strings that do not end with the suffix are returned unchanged.
v2_0_ref
name parent
strings.trimSuffix Strings
301
/v2.0/reference/flux/functions/strings/trim
/v2.0/reference/flux/functions/strings/trimleft
/v2.0/reference/flux/functions/strings/trimright
/v2.0/reference/flux/functions/strings/trimprefix
/v2.0/reference/flux/functions/strings/trimspace

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

import "strings"

strings.trimSuffix(v: "123_abc", suffix: "abc")

// 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
import "strings"

data
  |> map(fn: (r) => ({
      r with
      sensorID: strings.trimSuffix(v: r.sensorId, suffix: "_s12")
    })
  )