请编写代码将TStringList的重复项删除。

Posted on 2013-04-28 23:31  勒布朗.詹姆斯  阅读(211)  评论(0)    收藏  举报
//remove duplicate strings from the string list
 procedure RemoveDuplicates(const stringList : TStringList) ;
 var
   buffer: TStringList;
   cnt: Integer;
 begin
   stringList.Sort;
   buffer := TStringList.Create;
   try
     buffer.Sorted := True;
     buffer.Duplicates := dupIgnore;    //这个表示的是重复荐删除。
     buffer.BeginUpdate;
     for cnt := 0 to stringList.Count - 1 do
       buffer.Add(stringList[cnt]) ;
     buffer.EndUpdate;
     stringList.Assign(buffer) ;
   finally
     FreeandNil(buffer) ;
   end;
 end;

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3