文本替换

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    FileListBox1: TFileListBox;
    DirectoryListBox1: TDirectoryListBox;
    DriveComboBox1: TDriveComboBox;
    FilterComboBox1: TFilterComboBox;
    Button2: TButton;
    ProgressBar1: TProgressBar;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  f,f1,files : textfile;
  s,s1,s2 : string;
  source,target,str,ss : string;
  i: integer;
begin
  progressbar1.Min:=0;
  progressbar1.Max:=filelistbox1.Count-1;

  for i:=0 to filelistbox1.Count-1 do
  begin

    s:=filelistbox1.Items[i];
    assignfile(f,s);
    reset(f);
    assignfile(f1,'temp.txt');
    rewrite(f1);

    while not eof(f) do
    begin
      readln(f,s1);

      assignfile(files,'zk.dat');
      reset(files);
      while not eof(files) do
      begin
        readln(files,ss);
        if pos('::',ss)>0 then
        begin
          source:=copy(ss,0,pos('::',ss)-1);
          target:=copy(ss,pos('::',ss)+2,length(ss)-pos('::',ss)-1);
          s2:=stringreplace(s1,source,target,[rfReplaceAll]);
          s1:=s2;
        end;
      end;
      closefile(files);


      writeln(f1,s1);
    end;

    closefile(f1);
    closefile(f);
    deletefile(s);
    rename(f1,s);
    progressbar1.Position:=progressbar1.Position+1;
  end;
  showmessage('ok^g^');
  progressbar1.Position:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

end.

你可能感兴趣的:(文本替换)