strings.lastIndexAny() function

The strings.lastIndexAny() function returns the index of the last instance of any specified characters in a string. If none of the specified characters are present, the function returns -1.

*Output data type: Integer*

  1. import "strings"
  2. strings.lastIndexAny(v: "chicken", chars: "aeiouy")
  3. // returns 5

Parameters

v

The string value to search.

*Data type: String*

chars

Characters to search for.

*Data type: String*

Examples

Find the last occurrence of characters from a string
  1. import "strings"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. charLastIndex: strings.lastIndexAny(v: r._field, chars: "_-")
  6. })
  7. )

Related articles