调试运行ok;
我用了两个stringlist类,目的是把数据的分析都放在内存中,以加快速度;
TStringList(aStrings).Sort;排序也是为了加快速度
procedure TForm1.Button1Click(Sender: TObject);
function isRepetiton(sTemp: string;aStrings: TStrings):boolean;
var
i,iCount: integer;
begin
result:= false;
iCount:= 0;
if Assigned(aStrings) then
for i:=0 to aStrings.Count-1 do
if aStrings.Strings= sTemp then
begin
inc(iCount);
if iCount>=2 then
begin
Result:= true;
Break;
end;
end;
end;
var
aStrings,bStrings: TStrings;
i: integer;
begin
aStrings:= TStringList.Create;
bStrings:= TStringList.Create;
aStrings.Assign(Memo1.Lines);
TStringList(aStrings).Sort;
try
for i:= 0 to aStrings.Count-1 do
begin
if not isRepetiton(aStrings.Strings,aStrings) then
bStrings.Add(aStrings.Strings);
end;
Memo1.Lines.Assign(bStrings);
finally
aStrings.Free;
bStrings.Free;
end;
end;