function Extract(const S: string): Substring; overload;
Removes the first item equal to S without freeing its object, and returns it.
| # | Name | Description |
|---|---|---|
| 1 | S | The text, every text kind. |
Returns: Substring - The item, read in place; the empty text when no item is equal to S.
Remarks:
The returned Substring reads a short item's characters in place until the next add takes its place; a long item's memory passes to it, so it outlives the list.
Examples
Taking an item out.
uses Substr;
procedure Example;
var List: TSubstringList;
s: Substring;
begin
List := TSubstringList.Create(4);
try
List.Add('keep');
List.Add('take');
s := List.Extract('take');
Assert(s = 'take');
Assert(List.Count = 1);
finally
List.Free;
end;
end;
A long item outlives the list.
uses Substr;
procedure Example;
var List: TSubstringList;
s: Substring;
begin
List := TSubstringList.Create(2);
try
List.Add(Substring.Create('x', 600));
s := List.Extract(List[0]);
finally
List.Free;
end;
Assert((s.Length = 600) and (s[0] = 'x'));
end;
See Also: TSubstringList.ExtractItem, TSubstringList.Remove