怎么对所选择的文本文件内容进行操作?
 
  
 
         例如 c:\1.txt
                 其内容为 
123
123
.
.
.
.
321
123
此类。我想先对于123进行查找后再对他进行替换?请教高手。

解决方案 »

  1.   

    选用中间控件
    比如Memo
    你先把文本的内容导入到Memo里
    然后再对Memo里的内容进行操作
    达到要求后
    在SavetoFile导出文件
      

  2.   

    但是我的选择不只是一个文件,我需要对很多文件进行批量处理。而DEMO能够分别对他们进行文件识别吗?
      

  3.   

    可以用 stringlist 装载文件,然后再匹配修改....
      

  4.   

    var
      st:TStringList;
      i:Integer;
    begin
      st:=TStringList.Create;
      st.LoadFromFile('c:\1.txt');
      if st.Find('123',i) then
        st.Strings[i]:='567';
      st.SaveToFile('c:\1.txt');
    end;
      

  5.   

    哦,
    var 
      st:TStringList; 
      i:Integer; 
    begin 
      st:=TStringList.Create; 
      st.LoadFromFile('c:\1.txt'); 
      if st.Find('123',i) then 
        st.Strings[i]:='567';//567为你需要替换的东西 
      st.SaveToFile('c:\1.txt');
      st.free;  
    end;
    上面忘记释放了
      

  6.   

    文件不大就这样:
    procedure FileTextReplace(AFileName, NewFileName, OldStr, NewStr: string);
    var
      sl: TStringList;
    begin
      sl := TStringList.Create;
      try
        sl.LoadFromFile(AFileName);
        sl.Text := StringReplace(sl.Text, OldStr, NewStr, [rfReplaceAll]);
        sl.SaveToFile(NewFileName);
      finally
        sl.Free;
      end;
    end;