TSubstringList.ExtractItem Method

function ExtractItem(const S: string; const Direction: TDirection): Substring; overload;

Extract from either end: the first (FromBeginning) or last (FromEnd) item equal to S.

#NameDescription
1S

The text, every text kind.

2Direction

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

Returns: Substring - The item, as Extract returns it; the empty text when no item is equal to S.

Examples

Taking the last match out.

uses Substr, System.Types;

procedure Example;
var List: TSubstringList;
    s: Substring;
begin
    List := TSubstringList.Create(4);
    try
        List.Add('a');
        List.Add('b');
        List.Add('a');
        s := List.ExtractItem('a', FromEnd);
        Assert((s = 'a') and (List.Count = 2) and (List[1] = 'b'));
    finally
        List.Free;
    end;
end;
See Also: TSubstringList.Extract