怎样对文本文件中的字符串进行替换,文本文件比较大,不能用Tmemo读写

解决方案 »

  1.   

    AnsiReplaceStr(字符串,待替换的字符串,替换后的字符串)用这个函数有uses StrUtils
      

  2.   

    请hnhb(不死鸟)写的具体些,怎样读文件,怎样替换进去? 因为我用过stringreplace();但问题是不能对文件进行写(我用reset打开文件,用readln()读,然后再用替换函数,再用writeln()写.出错I/O 105)
      

  3.   

    如你這樣readln, writeln的, 最好寫到一個新的文件里!!
      

  4.   

    aiirii(ari) 兄没有有不重新写一个文件的方法呢
      

  5.   

    用TFileStream和TStringStream配合,一定可以。
      

  6.   

    procedure TDelForm.Button3Click(Sender: TObject);
    var
       TestFile: System.text;
       path,Str:string;
       j:integer;
    begin
        StrList:= TstringList.Create;
        GetDir(0,path);
        if not FileExists(path+'\yy.txt') then
        begin
           showmessage('NO FILE');
           ABORT;
        end;
        AssignFile(TestFile,path+'\yy.txt');
        //SetTextBuf(TestFile,80000);
        Reset(TestFile);
        while Not Eof(TestFile) do
        begin
           ReadLn(TestFile,Str);
           StrList.Add(str);
           memo1.Lines.Add(str);
        end;    memo1.Clear ;
        for j:=0 to StrList.Count-1 do
        begin
            AnsiReplaceStr(StrList[j],'A','9');
            Memo1.Lines.Add(StrList[j])  ;
            WriteLn(TestFile,StrList[j]);
            showmessage(StrList[j]);
        end;    CloseFile(TestFile);
    end;