txt文件中每个记录占一行 A000000
A000001
A000002
A000003
A000004
A000002
A000005
A000006
...数据不超过5000行如何找出这些记录中重复的并将重复的删除.
例如上面记录中A000002 是重复的,则在这些记录中剔除A000002

解决方案 »

  1.   

    list.add('A000000 ');
    list.add('A000002 ');
    list.add('A000002 ');
    list.add('A000001 ');
    list.add('A000003 ');
    for i:=0 to list.count -1 do begin
      if blist.indexof(list[i]) < 0 then 
        blist.add(list[i])
    end; 
    这还没怎么高效
    只能搞笑
      

  2.   

    楼主的快接近了
    procedure TForm1.Button1Click(Sender: TObject);
    var
      sl: tstringlist;
      f: textfile;
      s: string;
    begin
      sl:= tstringlist.Create;
      AssignFile(f, 'd:\abc.txt');
      reset(F);
      while not eof(F) do
      begin
        Readln(F, s);
        if sl.IndexOf(s) = -1 then
          sl.Append(s);
      end;
      CloseFile(f);
      sl.SaveToFile('d:\abc.txt');
      sl.Free;
    {abc.txt :
    A000000
    A000001
    A000002
    A000003
    A000004
    A000002
    A000005
    A000006
      }
    end;
      

  3.   

    开一个5000个大小的Boolean型数组,首先初始化为FALSE,查到一个数(忽略首字母A)就将对应的下标的值标记为TRUE,如果原来就是TRUE就是重复的,删除之。
    只需要遍历一次就可以找出所有的重复数据。
      

  4.   

    把你的文本内容Load到ListBox当中,ListBox.Sorted设置为true进行排序.先进行排序,再进行比较,这样效率会更高.procedure TForm1.FormCreate(Sender: TObject);
    begin
      ListBox1.Clear;
      ListBox1.Items.Add('2');
      ListBox1.Items.Add('1');
      ListBox1.Items.Add('3');
      ListBox1.Items.Add('2');
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      i: integer;
    begin
      ListBox1.Sorted := True;
      i := 0;
      while (i < ListBox1.Count - 2) do
      begin
        if ListBox1.Items.Strings[i] = ListBox1.Items.Strings[i+1] then
        begin
           ListBox1.Items.Delete(i+1);
           Continue;
        end;
        Inc(i);
      end;
    end;
      

  5.   

    如果允许排序的话,简单的方法:
    slstData.Sorted := True;
    slstData.Duplicates := dupIgnore;
    如果要求不改变原来的顺序,我的思路是:
    把数据插入到一个排序的列表中,在插入过程中,使用算法(简单的如二分法)查找列表中是否存在,如果存在,把存在的行次记录到另外一个列表中,统计完成后,删除这些行次的数据
      

  6.   


    我用SQL自增列再交叉导出的数据,结果是一样,1秒
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      V: tstringlist;
      i:Integer;
    begin
      V:= tstringlist.Create;
      V.LoadFromFile('d:\abc.txt');
      i:=V.Count-1;
      if i=0 then
        Exit;  while 1=1 do
       begin
         if V.IndexOf(V.Strings[i]) <> i then
            V.Delete(i);
         Dec(i);
         if i=0 then
           Break;
       end;  V.SaveToFile('d:\abc.txt');
    end;
      

  8.   

    用PilotEdit,http://topic.csdn.net/u/20090818/22/df665ee5-bd6f-4c6d-84b6-9831217e4e02.html
    点一下排序按钮就可以了。
      

  9.   


    弄过个小东西,分析一个txt文件,根据内容分类成多个新的txt文件,用的就这个方法感觉很快