docs-v2/content/influxdb/cloud/reference/flux/stdlib/strings/lastindex.md

1.2 KiB

title description aliases menu weight related
strings.lastIndex() function The strings.lastIndex() function returns the index of the last instance of a substring in a string or `-1` if substring is not present.
/influxdb/cloud/reference/flux/functions/strings/lastindex/
influxdb_cloud_ref
name parent
strings.lastIndex Strings
301
/influxdb/cloud/reference/flux/stdlib/strings/index/
/influxdb/cloud/reference/flux/stdlib/strings/indexany/
/influxdb/cloud/reference/flux/stdlib/strings/lastindexany/

The strings.lastIndex() function returns the index of the last instance of a substring in a string. If the substring is not present, the function returns -1.

Output data type: Integer

import "strings"

strings.lastIndex(v: "go gopher", substr: "go")

// returns 3

Parameters

v

The string value to search.

Data type: String

substr

The substring to search for.

Data type: String

Examples

Find the last occurrence of a substring
import "strings"

data
  |> map(fn: (r) => ({
      r with
      the_index: strings.lastIndex(v: r.pageTitle, substr: "the")
    })
  )