TSubstringList.IndexOfItem Method

function IndexOfItem(const S: string; const Direction: TDirection): Integer; overload;

IndexOf from either end: FromBeginning the first item equal to S, FromEnd the last; -1 when there is none.

#NameDescription
1S

The text, every text kind.

2Direction

FromBeginning: the first equal item; FromEnd: the last.

Returns: Integer - The item's index, or -1.

Examples

The last match.

uses Substr, System.Types;

procedure Example;
var List: TSubstringList;
begin
    List := TSubstringList.Create(4);
    try
        List.Add('x');
        List.Add('y');
        List.Add('x');
        Assert(List.IndexOfItem('x', FromBeginning) = 0);
        Assert(List.IndexOfItem('x', FromEnd) = 2);
    finally
        List.Free;
    end;
end;
See Also: TSubstringList.IndexOf