Creator Help

lastIndexOf

This topic describes the syntax and usage of the lastIndexOf function in Zoho Creator .

Description

The lastIndexOf function returns the position of the last occurrence of a specified value in a string.  The positions within the string starts with zero , the second position is 1, the third is 2 etc.  This method returns -1 if the value to search for never occurs.

Note: The lastIndexOf() method is case sensitive!

Syntax

<string>.lastIndexOf(<substring>)

(or)

lastIndexOf(<string>, <substring>)

// this format is supported only in the free flow scripting mode of Script builder.

The lastIndexOf function syntax has the following arguments.

string - Required. The main string to search for.

substring - Required. At which position to start the search

Return Value

Returns a number which refers to the position of the last occurrence of a specified value in a string or -1 if it never occurs.

Example

text="Hello world, welcome to the universe";

text.lastIndexOf("e");   //returns 35

text.lastIndexOf("H");   //returns 0

text.lastIndexOf("z");   //returns -1

lastIndexOf("Hello world, welcome to the universe","e");   //returns 35

lastIndexOf("Hello world, welcome to the universe","H");   //returns 0

lastIndexOf("Hello world, welcome to the universe","z");   //returns -1

Top