docs-v2/content/flux/v0.x/stdlib/strings/index-func.md

1.1 KiB

title description aliases menu weight related introduced
strings.index() function The strings.index() function returns the index of the first instance of a substring in another string.
/influxdb/v2.0/reference/flux/functions/strings/index-func/
/influxdb/v2.0/reference/flux/stdlib/strings/index-func/
/influxdb/cloud/reference/flux/stdlib/strings/index-func/
flux_0_x_ref
name parent
strings.index strings
301
/flux/v0.x/stdlib/strings/indexany/
/flux/v0.x/stdlib/strings/lastindex/
/flux/v0.x/stdlib/strings/lastindexany/
0.18.0

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

Output data type: Integer

import "strings"

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

// returns 0

Parameters

v

The string value to search.

substr

The substring to search for.

Examples

Find the first occurrence of a substring
import "strings"

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