yehiaeg
25th November 2004 15:32 UTC
Replace Problems
hello,
i'm simply trying to replace some words in a string,
i found 2 functions in the archive, each one have its problems:
1.StrReplace: Replace only first occurence of the "replace string",
2.WordReplace: will erase all the string if the "replace string" was not found in the string.
so anyone could modify any of these 2 functions to correct their problems?
Thanks In Advance
Yehia
Afrow UK
25th November 2004 15:46 UTC
I'll write a new function when I get home (I like writing them [sad but true]!)
-Stu
yehiaeg
25th November 2004 16:02 UTC
really appreciate it
Afrow UK
25th November 2004 17:35 UTC
I found the problem with the original StrReplace function.
If the occurance of the string to replace is at the end of the string, then a replacement never takes place (the function misses it).
Put this in:
IntOp $3 $3 - 1
After:
IntOp $3 $3 + $7
-Stu
yehiaeg
25th November 2004 22:32 UTC
thanks man
Instructor
26th November 2004 08:54 UTC
2.WordReplace: will erase all the string if the "replace string" was not found in the string.
Yes it return
errorlevel (before use any function read what this function do :().
Use the following:
StrCpy $R0 "AAA BBB CCC"
Push "$R0"
Push "XXX"
Push "xxx" ; replace with
Push "+"
Call WordReplace
Pop $R1 ;$R1 now contain errorlevel: "1" (XXX not found)
IfErrors 0 +2
StrCpy $R1 $R0 ;$R1 now contain: "AAA BBB CCC"
yehiaeg
26th November 2004 09:09 UTC
thanks again