---
title: strings.compare() function
description: strings.compare() compares the lexicographical order of two strings.
url: https://docs.influxdata.com/flux/v0/stdlib/strings/compare/
estimated_tokens: 579
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/strings/compare/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.18.0+

InfluxDB support

`strings.compare()` compares the lexicographical order of two strings.

#### Return values

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

##### Function type signature

```js
(t: string, v: string) => int
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### v

(Required)
String value to compare.

### t

(Required)
String value to compare against.

## Examples

### Compare the lexicographical order of column values

```js
import "strings"

data
    |> map(fn: (r) => ({r with same: strings.compare(v: r.string1, t: r.string2)}))
```

[](#view-example-input-and-output)

View example input and output

#### Input data

|        time        | string1  | string2  |
|--------------------|----------|----------|
|2022-01-01T00:00:00Z|RJqcVGNlcJ|rjQCvGNLCj|
|2022-01-01T00:01:00Z|unfbcNAXUA|hBumdSljCQ|
|2022-01-01T00:02:00Z|ITcHyLZuqu|ITcHyLZuqu|
|2022-01-01T00:03:00Z|HyXdjvrjgp|hyxDJvrJGP|
|2022-01-01T00:04:00Z|SVepvUBAVx|GuKKjuGsyI|

#### Output data

|same| string1  | string2  |        time        |
|----|----------|----------|--------------------|
|\-1 |RJqcVGNlcJ|rjQCvGNLCj|2022-01-01T00:00:00Z|
| 1  |unfbcNAXUA|hBumdSljCQ|2022-01-01T00:01:00Z|
| 0  |ITcHyLZuqu|ITcHyLZuqu|2022-01-01T00:02:00Z|
|\-1 |HyXdjvrjgp|hyxDJvrJGP|2022-01-01T00:03:00Z|
| 1  |SVepvUBAVx|GuKKjuGsyI|2022-01-01T00:04:00Z|
| Comparison | Return value |
| --- | --- |
| Comparison | Return value |
| v < t | -1 |
| v == t | 0 |
| v > t | 1 |

| time | string1 | string2 |
| --- | --- | --- |
| time | string1 | string2 |
| 2022-01-01T00:00:00Z | RJqcVGNlcJ | rjQCvGNLCj |
| 2022-01-01T00:01:00Z | unfbcNAXUA | hBumdSljCQ |
| 2022-01-01T00:02:00Z | ITcHyLZuqu | ITcHyLZuqu |
| 2022-01-01T00:03:00Z | HyXdjvrjgp | hyxDJvrJGP |
| 2022-01-01T00:04:00Z | SVepvUBAVx | GuKKjuGsyI |

| same | string1 | string2 | time |
| --- | --- | --- | --- |
| same | string1 | string2 | time |
| -1 | RJqcVGNlcJ | rjQCvGNLCj | 2022-01-01T00:00:00Z |
| 1 | unfbcNAXUA | hBumdSljCQ | 2022-01-01T00:01:00Z |
| 0 | ITcHyLZuqu | ITcHyLZuqu | 2022-01-01T00:02:00Z |
| -1 | HyXdjvrjgp | hyxDJvrJGP | 2022-01-01T00:03:00Z |
| 1 | SVepvUBAVx | GuKKjuGsyI | 2022-01-01T00:04:00Z |
