Siebel eScript Language Reference > Methods Reference > String Methods >

Search String for Last Substring Method


The Search String for Last Substring method searches the stringVar variable for the string that you specify in the substring argument. It returns the position of the last occurrence of this string in a string.

If any of the following situations is true, then it returns a value of negative 1:

  • It does not find the value that you specify in the substring argument.
  • The value you specify in the offset argument is outside the range of positions in the string.

Note the following:

  • To limit the search to a string of leftmost characters of the string, you can use the offset argument.
  • The first character of the substring must occur at a position that is no greater than the offset.
  • If the value you specify in the substring argument does not occur entirely before or at the offset, then the Search String for Last Substring method still returns the position of the substring that it finds.

This method uses the same arguments as the Search String for Substring method. For more information, see Table 43.

Format

stringVar.lastIndexOf(substring [, offset])

This method does the following according to how you specify the offset argument:

  • You do specify the offset argument. It searches the string up to the position that you specify in the offset argument, and then returns the rightmost position where the substring begins. It does not consider any substring that occurs after the position that you specify in the offset argument.
  • You do not specify the offset argument. It returns the rightmost position in the entire string where the substring begins.
Example 1

The following example returns the position of the last occurrence of the a character in the string. It returns a value of 5:

var string = "what a string";
string.lastIndexOf("a")

Example 2

The following example returns the position of the last occurrence of the abr string, beginning at a position that is not greater than 8. It returns a value of 7:

var magicWord = "abracadabra";
var lastabr = magicWord.lastIndexOf("abr", 8);

Siebel eScript Language Reference Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices.