Archive: Replace Problems


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


I'll write a new function when I get home (I like writing them [sad but true]!)

-Stu


really appreciate it


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


thanks man


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"

thanks again