String.LastIndexOf

Syntax

LastIndexOf(Value: String; [StartIndex: Integer = -1;] [Count: Integer = -1]): Integer;

Parameters

Value. The substring, which should be searched for in the string.

StartIndex. The position, starting from which the search is executed.

Count. The number of places, in which the search is executed.

Description

The LastIndexOf method returns the index of the last occurrence of the substring passed in the Value parameter in the current string.

Comments

The search starts from the StartIndex place and continues in the reverse direction (from right to left) in the Count places. By default, the StartIndex and Count parameters have the -1 value, in this case the search goes from the end of strings and continues to the string beginning until the substring is found, which is specified in Value, or the first string character is reached.

If the specified substring is not found in the source string, the method returns -1. Characters are case-sensitive.

Example

Sub UserProc;
Var
    s, s1, s2: String;
    i, i1: Integer;
Begin
    s := "abecdef";
    s1 := "E";
    s2 := "g";
    i := S.LastIndexOf(S1);
    i1 := S.LastIndexOf(S2);
End Sub UserProc;

After executing the example the "i" variable will contain the "5" value, and the "i1" variable contains the "-1" value.

See also:

String