各位大哥大姐:
  小弟想实现如下功能,具体如下:
  1)已有一个txt文档,内容为:
     aaa  bbb  ccc  ddd
     eee  fff  ggg  hhh
     e333 4rrr 2fff f333
     i888 i999 i900 i322
  2) 在该文档的第二行、第三列的“ggg”后面加入“b”字符,即为“gggb”,文档变为
     aaa  bbb  ccc  ddd
     eee  fff  gggb  hhh
     e333 4rrr 2fff f333
     i888 i999 i900 i322    该如何实现呢?    小弟初学乍道,还请说的详细点呀!
    谢谢!

解决方案 »

  1.   


    procedure TForm1.BitBtn59Click(Sender: TObject);
    var
      sList:TStringList;
      s:string;
    begin
      sList:=TStringList.Create;
      sList.LoadFromFile('Test.txt');
      s:=sList.Text;
      s:=StringReplace(s,'ggg','gggb',[rfReplaceAll]);
      sList.Text:=s;
      sList.SaveToFile('Test01.txt');
      FreeAndNil(sList);
    end;
      

  2.   

    替换文本的话 最方便的就是 s := StringReplace(s, 'ggg' ,'gggb', [rfReplaceAll]);  这种了
      

  3.   

    这样写 不行,效率,效率,主要效率。var 
    textfile :TTextFile;
    begin
    testfile = fileopen("filename.txt",readandwrite);
    while(feof(textfile)) begin
    if () then begin
    filewrite(testfilee,1,'b');
    end;
    end;
    closefile(textfile);
    end;