docs-v2/content/flux/v0.x/stdlib/strings/compare.md

1.1 KiB

title description aliases menu weight introduced
strings.compare() function The strings.compare() function compares the lexicographical order of two strings.
/influxdb/v2.0/reference/flux/functions/strings/compare/
/influxdb/v2.0/reference/flux/stdlib/strings/compare/
/influxdb/cloud/reference/flux/stdlib/strings/compare/
flux_0_x_ref
name parent
strings.compare strings
301 0.18.0

The strings.compare() function compares the lexicographical order of two strings.

Output data type: Integer

import "strings"

strings.compare(v: "a", t: "b")

// returns -1

Return values

Comparison Return value
v < t -1
v == t 0
v > t 1

Parameters

v

The string value to compare.

t

The string value to compare against.

Examples

Compare the lexicographical order of column values
import "strings"

data
    |> map(fn: (r) => ({r with _value: strings.compare(v: r.tag1, t: r.tag2)}))