Die von Frank beschriebene Methode kenne ich aus meiner code library:
Delphi-Quellcode:
procedure KeepDuplicates(sl: TStringList; allDuplicates: boolean = false);
var
i, dist: integer;
begin
if not sl.Sorted then
sl.Sort;
for i := sl.Count - 1 downto 0 do begin
dist := i - sl.IndexOf(sl[i]);
if dist > i then Continue;
if (dist = 0) or (not allDuplicates and (dist > 1)) then
sl.Delete(i);
end;
end;
Grüße vom marabu