Blame | Last modification | View Log | RSS feed
;------------------------------------------------------------------------------; Code originally from http://nsis.sourceforge.net/StrRep;; Description; This function searches and replaces all occurrences of a substring in a string.;; Usage/Syntax; !include StrRep.nsh; ; instantiate the function for either the installer/uninstaller or both; !insertmacro Func_StrRep ""; !insertmacro Func_StrRep "un."; [...]; ; and now use the macro to call the function; ${StrRep} '$0' 'C:\Documents and Settings\Dan\Desktop\PSCP Frontend.exe' '\' '\\'; MessageBox MB_OK $0 ; will be C:\\Documents and Settings\\Dan\\Desktop\\PSCP Frontend.exe;;Parameters; ${StrRep} "$result_var" "String" "SubString" "RepString";; $result_var; Variable where resulting operation of the replacement is returned.; If SubString is not found, the value is the same as String.;; String; String where to search for SubString.;; SubString; String to search in String and to be replaced by RepString.;; RepString; String to replace all occurrences of SubString inside String.;;------------------------------------------------------------------------------!define StrRep "!insertmacro StrRep"!macro StrRep output string old newPush "${string}"Push "${old}"Push "${new}"!ifdef __UNINSTALL__Call un.StrRep!elseCall StrRep!endifPop ${output}!macroend!macro Func_StrRep unFunction ${un}StrRepExch $R2 ;newExch 1Exch $R1 ;oldExch 2Exch $R0 ;stringPush $R3Push $R4Push $R5Push $R6Push $R7Push $R8Push $R9StrCpy $R3 0StrLen $R4 $R1StrLen $R6 $R0StrLen $R9 $R2loop:StrCpy $R5 $R0 $R4 $R3StrCmp $R5 $R1 foundStrCmp $R3 $R6 doneIntOp $R3 $R3 + 1 ;move offset by 1 to check the next characterGoto loopfound:StrCpy $R5 $R0 $R3IntOp $R8 $R3 + $R4StrCpy $R7 $R0 "" $R8StrCpy $R0 $R5$R2$R7StrLen $R6 $R0IntOp $R3 $R3 + $R9 ;move offset by length of the replacement stringGoto loopdone:Pop $R9Pop $R8Pop $R7Pop $R6Pop $R5Pop $R4Pop $R3Push $R0Push $R1Pop $R0Pop $R1Pop $R0Pop $R2Exch $R1FunctionEnd!macroend