strings.lastIndex() function

Warning! This page documents an earlier version of Flux, which is no longer actively developed. Flux v0.50 is the most recent stable version of Flux.

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