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

1.0 KiB

title description menu weight related
strings.indexAny() function The strings.indexAny() function returns the index of the first instance of specified characters in a string.
v2_0_ref
name parent
strings.indexAny Strings
301
/v2.0/reference/flux/functions/strings/index-func/
/v2.0/reference/flux/functions/strings/lastindex/
/v2.0/reference/flux/functions/strings/lastindexany/

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.

Data type: String

chars

Characters to search for.

Data type: String

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: "_-")
    })
  )