StrReplace: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(SF: orginal -> original.)
m (Updated author and download links, and changed format of some pages.)
Line 75: Line 75:
Written by Hendri Adriaens aka [[user:Smile2Me | Smile2Me]]...
Written by Hendri Adriaens aka [[user:Smile2Me | Smile2Me]]...


Page author: sunjammer
Page author: [[User:sunjammer|sunjammer]]

Revision as of 12:17, 23 April 2005

Description

This function replaces a substring by another substring. This doesn't work with Unicode.

The Function With Example

; 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

Version History

25 Oct. 2004
Fixed a bug with replacement of adjacent matches (Afrow UK).

Credits

Written by Hendri Adriaens aka Smile2Me...

Page author: sunjammer