编程问题:如何在一个文本文件(如Txt)中,比较n行字符, 删除重复的字符串行,请见示例: 
This is a test.
This is a test.
This is another test.
This is another test.
This is another test.
This is a test.
This is a test.
This is another test.删除其中重复的内容,变成:
This is a test.
This is another test.

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      sw:boolean;
      i,cou:integer;
      s:string;
      fulltxt,newfulltxt:TStringList;begin
      fullTxt := TStringList.Create;
      newfulltxt := Tstringlist.Create;
      fullTxt.LoadFromFile('abc.txt');  for i :=0 to fulltxt.Count-1 do
        begin
              sw:=false;
              s:= fulltxt.Strings[i];
              if i=0 then
               begin
                newfulltxt.Add(s);
                Continue;
               end;          for cou := 0 to newfulltxt.Count-1 do
               if AnsiSameStr(s,newfulltxt.Strings[cou]) then
                  sw := true;          if not sw then
                newfulltxt.Add(s);    end;
      newfulltxt.SaveToFile('abc.txt');
    end;