Replace a text in a file with Inno Setup

前端 未结 1 1297
北恋
北恋 2020-12-09 06:26

Hi I have a problem with replacing a text in a textfile with Inno Setup (Delphi based).

My Code:

procedure         


        
相关标签:
1条回答
  • 2020-12-09 07:24

    I hope this function does the job:

    function FileReplaceString(const FileName, SearchString, ReplaceString: string):boolean;
    var
      MyFile : TStrings;
      MyText : string;
    begin
      MyFile := TStringList.Create;
    
      try
        result := true;
    
        try
          MyFile.LoadFromFile(FileName);
          MyText := MyFile.Text;
    
          { Only save if text has been changed. }
          if StringChangeEx(MyText, SearchString, ReplaceString, True) > 0 then
          begin;
            MyFile.Text := MyText;
            MyFile.SaveToFile(FileName);
          end;
        except
          result := false;
        end;
      finally
        MyFile.Free;
      end;
    end;
    

    Kudos to TLama for feedback.

    0 讨论(0)
提交回复
热议问题