Substring.LastIndexOf Method

Overload List

#SignatureDescription
1function LastIndexOf(const C: Char): Integer; overload;
2function LastIndexOf(const C: Char; const StartIndex: Integer): Integer; overload;
3function LastIndexOf(const C: Char; const StartIndex, Count: Integer): Integer; overload;
4function LastIndexOf(const S: Substring): Integer; overload;The 0-based index of the last occurrence of S.
5function LastIndexOf(const S: string): Integer; overload;
6function LastIndexOf(const S: string; const StartIndex: Integer): Integer; overload;The last occurrence of S lying wholly inside [0, StartIndex], or inside the Count characters that end at StartIndex.
7function LastIndexOf(const S: string; const StartIndex, Count: Integer): Integer; overload;

Overload 1: function LastIndexOf(const C: Char): Integer; overload;

#NameTypeDescription
1CChar

Returns: Integer

Overload 2: function LastIndexOf(const C: Char; const StartIndex: Integer): Integer; overload;

#NameTypeDescription
1CChar
2StartIndexInteger

Returns: Integer

Overload 3: function LastIndexOf(const C: Char; const StartIndex, Count: Integer): Integer; overload;

#NameTypeDescription
1CChar
2StartIndexInteger
3CountInteger

Returns: Integer

Overload 4: function LastIndexOf(const S: Substring): Integer; overload;

The 0-based index of the last occurrence of S.

#NameTypeDescription
1SSubstring

Returns: Integer - The index, or -1 when there is none; an empty S is never found.

Examples

The last occurrence of a text and of a character.

uses Substr;

procedure Example;
var s: Substring;
begin
    s := Substring('banana');
    Assert(s.LastIndexOf('an') = 3);
    Assert(s.LastIndexOf(Char('a')) = 5);
end;

Overload 5: function LastIndexOf(const S: string): Integer; overload;

#NameTypeDescription
1Sstring

Returns: Integer

Overload 6: function LastIndexOf(const S: string; const StartIndex: Integer): Integer; overload;

The last occurrence of S lying wholly inside [0, StartIndex], or inside the Count characters that end at StartIndex.

#NameTypeDescription
1Sstring
2StartIndexInteger

Returns: Integer - The 0-based index, or -1.

Remarks:

StartIndex = -1 with Count = 0 is an empty range; a range outside the text raises ESubstringRangeError.

Examples

Searching back from a position.

uses Substr;

procedure Example;
var s: Substring;
begin
    s := Substring('banana');
    Assert(s.LastIndexOf('an', 2) = 1);
    Assert(s.LastIndexOf(Char('a'), 4, 2) = 3);
end;

Overload 7: function LastIndexOf(const S: string; const StartIndex, Count: Integer): Integer; overload;

#NameTypeDescription
1Sstring
2StartIndexInteger
3CountInteger

Returns: Integer