如何在最快的情况下去除不定长数组中的重复记录

解决方案 »

  1.   

    var
      strList: Tstringlist;
      isIn :boolean;
    begin
     for i:=low(Array) to High(Array) do
     begin
      isIn ;= false;
      for j:= 0 to strList.Count-1 do
      begin
         if Arrar[i]= strList[j] then
           isIn ;= true;
         if not isIn then
            strList.Add(Arrar[i]);
      ned;
    end;
      

  2.   

    var
      strList: Tstringlist;
      isIn :boolean;
    begin
     strList:= Tstringlist.Create;
     for i:=low(Array) to High(Array) do
     begin
      isIn := false;
      for j:= 0 to strList.Count-1 do
      begin
         if Arrar[i]= strList[j] then
           isIn := true;
         if not isIn then
            strList.Add(Arrar[i]);
      ned;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    str,str1:array of string;
    i,j,k:integer;
    begin
    setlength(str,memo1.Lines.Count);
    setlength(str1,memo1.Lines.Count);
    for i:=low(str) to high(str) do
    begin
    str[i]:=memo1.Lines.Strings[i];
    end;
    str1:=str;for j:=low(str1) to high(str1) do begin
    k:=0;
    for i:=low(str) to high(str) do
    begin
    if str1[j]='' then break;
    if str1[j]=str[i] then inc(k);
    if k>=2 then str1[j]:='';
    end;
    end;memo2.Clear ;
    for i:=low(str1) to high(str1) do
    begin
    if str1[i]='' then continue;
    memo2.Lines.Add(str1[i]);
    end;end;
      

  4.   

    memo1中放入您任意多lines的数据,并且有重复的!
    memo2中将会显示您筛选后的无重复的数据!
    您稍微改一下,就可以做一个通用的筛选函数了。呵呵:)
      

  5.   

    如果现在要出去重复记录,楼上已经给出参考代码。
    以后在数组中添加记录的时候可首先用一个循环判
    断将要添加记录是否和数组中的某条记录相同,
    if 相同 then 
    else
    ...