strings.indexAny() function

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*

  1. import "strings"
  2. strings.indexAny(v: "chicken", chars: "aeiouy")
  3. // 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
  1. import "strings"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. charIndex: strings.indexAny(v: r._field, chars: "_-")
  6. })
  7. )

Related articles