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
Replace \ with \\
5 posts
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.
You could first replace the backslashes with another character, like a hash, and then replace that character with a double backslash.
Done
Hello,
thanks a lot for your help.
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
Hello,
thanks a lot for your help.
Yes, good idea.Originally Posted by jpderuiter View PostI 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.
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
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).Originally Posted by hawkmaster View PostNo idea if you can do this easier.
!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
!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