fabiochelly
16th November 2005 13:49 UTC
Replace in file
Hi,
Currently, I use an external nsh file to replace text in files.
Is there a way to replace text in file with the integrated include nsh files: wordfunc, strfunc or else?
Something like:
${StrRepFile} "$FILEPATH" "oldtext" "newtext"
Instructor
16th November 2005 14:54 UTC
Name "Output"
OutFile "Output.exe"
!include "TextFunc.nsh"
!insertmacro LineFind
!include "WordFunc.nsh"
!insertmacro WordReplace
Section
${LineFind} "C:\ReplaceInFile.txt" "C:\ResultFile.txt" "1:-1" "LineFindCallback"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function LineFindCallback
${WordReplace} "$R9" "Replace this string" "Replace with this string" "+" $R9
Push $0
FunctionEnd
fabiochelly
16th November 2005 15:11 UTC
Thank you.
Is it normal to push $0 instead of $R9 at the end of the callback function?
And do you know if there is difference between StrRep and WordReplace?
Instructor
16th November 2005 15:15 UTC
Push $var ; If $var="StopLineFind" Then exit from function
; If $var="SkipWrite" Then skip current line (ignored if "/NUL")
fabiochelly
16th November 2005 15:34 UTC
What happen if I don't Push something at the end of the callback function? Or if I push an empty string?
Instructor
16th November 2005 18:14 UTC
If you don't use "StopLineFind", "SkipWrite", you can Push anything else "Push 0", "Push ''" ... You need to Push something, otherwise it will bring to stack corruption.
fabiochelly
16th November 2005 19:47 UTC
Thank you very much. It works fine.
By the way is there a difference between StrRep (from StrFunc.nsh) and WordReplace?
Instructor
16th November 2005 20:02 UTC
Read documentation