Hi,
In my installer, the user specify something that I Put in a variable. After that, I use a RiF Function with StrRep Function to Replace a String in a Txt file with variable created by the user input.
Exemple: User input: A2sd (i put that in $VarExemple)
In the script, I do :
!insertmacro ReplaceInFile "D:\somefile.txt" "_text" "$VarExemple"
The text file is like that :
Bla Bla Bla Bla Bla
Bla bla bla bla bla
I want to Some_textC tell you
Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla
The expected result would be :
Bla Bla Bla Bla Bla
Bla bla bla bla bla
I want to SomeA2sdC tell you
Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla
But here is what it does :
Bla Bla Bla Bla Bla
Bla bla bla bla bla
I want to SomeA2sd
C tell you
Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla
How to avoid the cariage return !!! Because of that cariage return, the file is screwed...
Thank you !
String Replace Problem...
4 posts
I've not tested it, but you could try this function:
Otherwise, you might want to post your current ReplaceInFile macro here and see if someone can help spot the problem.
Otherwise, you might want to post your current ReplaceInFile macro here and see if someone can help spot the problem.
Script uses header (for NSIS 2.07 or below):
Name "Output"
OutFile "Output.exe"
!include "TextFunc.nsh"
!insertmacro LineFind
!include "WordFunc.nsh"
!insertmacro WordReplace
Var ReplaceIt
Var ReplaceWith
Section
StrCpy $ReplaceIt "_text"
StrCpy $ReplaceWith "A2sd"
StrCpy $R0 0
${LineFind} "C:\input.txt" "C:\output.txt" "1:-1" "Example5"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "Changed lines=$R0"
SectionEnd
Function Example5
StrCpy $1 $R9
${WordReplace} '$R9' '$ReplaceIt' '$ReplaceWith' '+' $R9
StrCmp $1 $R9 +2
IntOp $R0 $R0 + 1
#$R0 count of changed lines
Push $0
FunctionEnd
How to avoid the cariage return !!! Because of that cariage return, the file is screwed...Ups, has not paid attention.
...
!include "TextFunc.nsh"
!insertmacro LineFind
!insertmacro TrimNewLines
...
StrCpy $ReplaceWith "A2sd"
${TrimNewLines} "$ReplaceWith" $ReplaceWith