Reference to the indexOf() and lastIndexOf() string manipulation functions

Summary

indexOf(metric|source|<pointTagKey>, "<subString>", <tsExpression>)

lastIndexOf(metric|source|<pointTagKey>, "<subString>", <tsExpression>)

The indexOf() function finds the first occurrence of the specified substring in the metadata string, and returns the starting position of that occurrence.

The lastIndexOf() function finds the last occurrence of the specified substring in the specified metadata string, and returns the starting position of that occurrence.

Parameters

ParameterDescription
metric|source|<pointTagKey> The metadata string (metric name, source name, or value of a point tag key) to find the substring in.
substring The substring that you want to check for.
tsExpression The expression that describes the time series with the metadata string to find the substring in.

Description

The indexOf() and lastIndexOf() function return a numeric index that indicates the starting position of a given substring in the specified metadata string:

  • indexOf() returns the index for the first occurrence of the substring.
  • lastIndexOf() returns the index for the last occurrence of the substring.

The returned indexes are displayed as metadata values in the chart legend or in a table column.

Numeric indexes are counted from left to right, starting with 0.

These functions return -1 if no occurrence of the specified substring are found.

Example

The following example uses string functions to get information about the value of the service point tag, which is dataingester.

  • We check where the string "ta" occurs in dataingester and get 2 (the index starts at 0).
  • We check for the last occurrence of "e" in dataingester and get 10, as shown in the hover text.

ts indexOf-lastIndexOf