删除重复的字符串行

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

编程问题:如何在一个文本文件(如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.

· 网友精彩回答:

发表者:uiwq

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;  
   
   
 

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved