lastIndexOf( )
Returns a number that represents the starting position of a string within another string. lastIndexOf( ) searches backward from the right end of the target string, and returns a value counting from the beginning of the target.
Syntax
<target expC>.lastIndexOf(<search expC> [, <from index expN>])
<target expC>
The string in which you want to search for <search expC>.
<search expC>
The string you want to search for in <target expC>.
<from index expN>
Where you want to start searching for the string. By default, dBASE Plus starts searching at the end of the string, index <target expC>.length – 1.
Property of
String
Description
This method is similar to the RAT( ) function, but in addition to the syntactic difference of being a method instead of a function and the fact that the position is zero-based, the optional parameter specifies where to start searching instead of the nth occurrence to find.
Use lastIndexOf( ) to search for the <search expC> in a target string, searching right to left, end to beginning, from the character at <from index expN> to the first character. The search is case-sensitive. Use toUpperCase( ) or toLowerCase( ) to make the search case-insensitive.
Even though the search starts from the end of the target string, lastIndexOf( ) returns an index representing where a search string begins in a target string, counting from the beginning of the target. The first character of the string is at index 0 and the last character is at index <target expC>.length – 1. If <search expC> occurs only once in the target, lastIndexOf( ) and indexOf( ) return the same value. For example, "abcdef".lastIndexOf("abc") and "abcdef".indexOf("abc") both return 0.
lastIndexOf( ) returns –1 when:
The search string isn’t found
The search string or target string is empty
The search string is longer than the target string
To find the starting position of <search expC>, searching from left to right, beginning to end, use indexOf( ).