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

1.2 KiB

title description aliases menu weight related introduced
strings.indexAny() function The strings.indexAny() function returns the index of the first instance of specified characters in a string.
/influxdb/v2.0/reference/flux/functions/strings/indexany/
/influxdb/v2.0/reference/flux/stdlib/strings/indexany/
/influxdb/cloud/reference/flux/stdlib/strings/indexany/
flux_0_x_ref
name parent
strings.indexAny strings
301
/flux/v0.x/stdlib/strings/index-func/
/flux/v0.x/stdlib/strings/lastindex/
/flux/v0.x/stdlib/strings/lastindexany/
0.18.0

The strings.indexAny() function returns the index of the first instance of specified characters in a string. If none of the specified characters are present, it returns -1.

Output data type: Integer

import "strings"

strings.indexAny(v: "chicken", chars: "aeiouy")

// returns 2

Parameters

v

The string value to search.

chars

Characters to search for.

Examples

Find the first occurrence of characters from a string
import "strings"

data
    |> map(fn: (r) => ({r with charIndex: strings.indexAny(v: r._field, chars: "_-")}))