请问各位大侠,
我现在想把两个文件读入,然后再把文件a的每一行和文件B比较,如果文件a的这一行在文件b中有了,则在文件b中删除这一行,最后得出文件c(c=b-a,差不多这个意思)
不知道该怎么做?
好像该用
好像该用AssignFile?怎么用啊?

解决方案 »

  1.   

    先写一个文件文件的
    var
      liA,liB,liC:TMemo;
      i,Index:integer;
      str:string;
    begin
      liA:=TMemo.Create(nil);
      liB:=TMemo.Create(nil);
      liC:=TMemo.Create(nil);
      liA.Lines.LoadFromFile('你的文件A');
      liB.Lines.LoadFromFile('你的文件B');
      for i:=0 to liB.Lines.count-1 do 
      begin
      str:=liB.Lines.Strings[i];
      index:=liA.Lines.indexof(str);
      if index<>-1 then  表示A中有
      begin
      end
      else
      liC.Lines.Add(str);
        end;
      liC.Lines.SaveToFile('你的文件C');
      Freeandnil(liA);
      Freeandnil(liB);
      Freeandnil(liC);
    end;
      

  2.   

    非常感谢
    2214391    DSL26516         0.00         0.00         0.00         0.00 夏明福                                  
    2214431    DSL48776         0.00         0.00         0.00     14074.00 李玲                                    
    2214438    DSL42381         0.00         0.00         0.00   1380602.00 陈宇        
    我的文件中的信息是这个样子的,我只需要比较一行的前7位就可以得出此行比较的结果了,请问该怎么取出这前七位进行比较?
      

  3.   

    这个啊,
    用clientDataset吧,很容易!
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      s1,s2,s3 : Tstringlist;
      i : integer;
    begin
      s1 := Tstringlist.Create;
      s2 := Tstringlist.Create;
      s3 := Tstringlist.Create;
      s1.LoadFromFile('c:\1.txt');
      s2.LoadFromFile('c:\2.txt');
      s3.LoadFromFile('c:\3.txt');
      for i:=0 to s2.Count-1 do
      begin
        if s1[i]<>s2[i] then
        s3.Add(s2[i]);
        //showmessage(s2[i]);
      end;
      s3.SaveToFile('c:\3.txt');
    end;
      

  5.   

    应你的要求,比较前7位,也就是编号:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      s1,s2,s3 : Tstringlist;
      i : integer;
    begin
      s1 := Tstringlist.Create;
      s2 := Tstringlist.Create;
      s3 := Tstringlist.Create;
      s1.LoadFromFile('c:\1.txt');
      s2.LoadFromFile('c:\2.txt');
      s3.LoadFromFile('c:\3.txt');
      for i:=0 to s2.Count-1 do
      begin
        if copy(s1[i],1,7)<>copy(s2[i],1,7) then
        s3.Add(s2[i]);
        //showmessage(s2[i]);
      end;
      s3.SaveToFile('c:\3.txt');
    end;
      

  6.   

    直接读到dataset里面很好处理嘛
      

  7.   

    我感觉也应该很简单,觉得直接上传到数据库作就可以了,但是用delphi就 不会了。初次接触,clientdataset找了好长时间才找到!大家可否再指点一下