我知道如何使用dupignore从已排序的TStringList中删除重复字符串。
CallData := TStringList.Create;
CallData.Sorted := True;
Call.Duplicates := dupIgnore;
但在我的情况下,字符串不应该被排序。
使用FOR循环查找重复项非常慢(即使使用indexOF()),当TStringList有数十万行时。
if OpenDialog1.Execute then
begin
Try
y := TStringList.create;
f := TStreamReader.create(OpenDialog1.FileName, TEncoding.UTF8, True);
while not f.EndOfStream do
begin
l := f.ReadLine;
X.Add(l);
end;
g := Tstreamwriter.create('d:\logX.txt', True, TEncoding.UTF8);
for I := 0 to X.count - 1 do
begin
if y.IndexOf(X[I]) = -1 then
y.Add(X[I]);
end;
for j := 0 to y.count - 1 do
g.WriteLine(y[j]);
Finally
f.free;
y.free;
g.free;
End;
end;
有没有更好的方法?