|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| {|align=right
| | #REDIRECT [[StrRep]] |
| |<small>Author: [[{{ns:2}}:sunjammer|sunjammer]] ([[{{ns:3}}:sunjammer|talk]], [[{{ns:-1}}:Contributions/sunjammer|contrib]])</small>
| |
| |}
| |
| <br style="clear:both;">
| |
| == Description ==
| |
| This function replaces a substring by another substring. This doesn't work with Unicode.
| |
| | |
| == The Function With Example ==
| |
| <highlight-nsis>; function StrReplace
| |
| ; by Hendri Adriaens
| |
| | |
| ; HendriAdriaens@hotmail.com
| |
| | |
| outfile StrReplace.exe
| |
| name StrReplace
| |
| | |
| section
| |
| Push "C:\my documents\my files\prob" ;original string
| |
| Push "\m" ;needs to be replaced
| |
| Push "\th" ;will replace wrong characters
| |
| Call StrReplace
| |
| Pop $0
| |
| MessageBox MB_OK $0
| |
| sectionend
| |
| | |
| function StrReplace
| |
| Exch $0 ;this will replace wrong characters
| |
| Exch
| |
| Exch $1 ;needs to be replaced
| |
| Exch
| |
| Exch 2
| |
| Exch $2 ;the original string
| |
| Push $3 ;counter
| |
| Push $4 ;temp character
| |
| Push $5 ;temp string
| |
| Push $6 ;length of string that need to be replaced
| |
| Push $7 ;length of string that will replace
| |
| Push $R0 ;tempstring
| |
| Push $R1 ;tempstring
| |
| Push $R2 ;tempstring
| |
| StrCpy $3 "-1"
| |
| StrCpy $5 ""
| |
| StrLen $6 $1
| |
| StrLen $7 $0
| |
| Loop:
| |
| IntOp $3 $3 + 1
| |
| Loop_noinc:
| |
| StrCpy $4 $2 $6 $3
| |
| StrCmp $4 "" ExitLoop
| |
| StrCmp $4 $1 Replace
| |
| Goto Loop
| |
| Replace:
| |
| StrCpy $R0 $2 $3
| |
| IntOp $R2 $3 + $6
| |
| StrCpy $R1 $2 "" $R2
| |
| StrCpy $2 $R0$0$R1
| |
| IntOp $3 $3 + $7
| |
| Goto Loop_noinc
| |
| ExitLoop:
| |
| StrCpy $0 $2
| |
| Pop $R2
| |
| Pop $R1
| |
| Pop $R0
| |
| Pop $7
| |
| Pop $6
| |
| Pop $5
| |
| Pop $4
| |
| Pop $3
| |
| Pop $2
| |
| Pop $1
| |
| Exch $0
| |
| FunctionEnd</highlight-nsis>
| |
| | |
| == Version History ==
| |
| ; 25 Oct. 2004
| |
| : Fixed a bug with replacement of adjacent matches ([[user:Afrow UK |Afrow UK]]).
| |
| | |
| == Credits ==
| |
| Written by Hendri Adriaens aka [[user:Smile2Me | Smile2Me]]...
| |
| | |
| [[{{ns:14}}:String Functions]]
| |