hawkmaster
16th April 2010 11:10 UTC
Replace \ with \\
Hello
I want to replace a placeholder in a file with the InstDir .
But the path should be with double backslashes.
e.g.
C:\\Program
I tried this:
Push "$INSTDIR" ;original string
Push "\" ;needs to be replaced
Push "\\" ;will replace wrong characters
Call StrReplace
Pop $0
Then MessageBox MB_OK $0 shows a lot of \\\\\\\\\\\\\\\\\\\\\\\\\\
what did I wrong or how can I do this?
regards
hawk
jpderuiter
16th April 2010 11:38 UTC
I guess when the first backslash is replaced, and the next character is checked, it'll see a backslash again, causing a infinite loop.
You could first replace the backslashes with another character, like a hash, and then replace that character with a double backslash.
hawkmaster
16th April 2010 12:05 UTC
Done
Hello,
thanks a lot for your help.
Originally posted by jpderuiter
I guess when the first backslash is replaced, and the next character is checked, it'll see a backslash again, causing a infinite loop.
You could first replace the backslashes with another character, like a hash, and then replace that character with a double backslash.
Yes, good idea.
I did it in this way:
Push "$INSTDIR" ;original string
Push "\" ;needs to be replaced
Push "#" ;will replace wrong characters
Call StrReplace
Pop $0
Push $0 ;original string
Push "#" ;needs to be replaced
Push "\\" ;will replace wrong characters
Call StrReplace
Pop $0
It works now. No idea if you can do this easier.
regards
hawk
MSG
16th April 2010 12:13 UTC
Originally posted by hawkmaster
No idea if you can do this easier.
Of course you can, but you'd need to edit the StrReplace function (or write your own, maybe as a macro to get rid of the push/pops).
jiake
19th April 2010 05:02 UTC
!include "MUI2.nsh"
!include "WordFunc.nsh"
Name "PROGRAM"
OutFile "Setup.exe"
InstallDir "$TEMP"
ShowInstDetails show
!insertmacro WordReplace
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section installl
StrCpy $0 "C:\\Program Files\\Internet Explorer\\iexplore.exe"
DetailPrint "original: $0"
${WordReplace} $0 "\\" "\" "+" $0
DetailPrint "replaced: $0"
Sectionend