如何去掉ListView中重复的行的内容,并且统计出重复行的条数?在线等。。。
如:
2000
2001
2001
2002
aaaa
aaaa
aaaa
....
去掉重复的后只有:
2000(1)
2001(2)
2002(1)
aaaa(3)
....
[解决办法]
//tstringlist举例,
var
tempList,strList:TStringList;
i:Integer;
begin
strList:= TStringList.Create;
tempList:= TStringList.Create;
try
strList.Add( 'aa ' );
strList.Add( 'aa ' );
strList.Add( 'aa ' );
strList.Add( 'aa ' );
strList.Add( 'bb ' );
strList.Add( 'bb ' );
strList.Add( 'bb ' );
for i:=0 to strList.Count-1 do
begin
if tempList.IndexOf( strList.Strings[ i ] ) = -1 then
begin
tempList.Add( strList.Strings[ i ] );
end else
begin
//重复记录。。。。+1
end;
end;
for i:=0 to tempList.Count-1 do
begin
self.Memo1.Lines.Add( tempList[ i ] );
end;
finally
tempList.Free;
strList.Free;
end;