Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Replace 3th letter in a string (http://forums.winamp.com/showthread.php?t=233051)

BioDuo 13th December 2005 08:07

Replace 3th letter in a string
 
How do I replace the third letter in a string

Example

$0 ReadRegStr HKCU "Software\BioDuo" "BioDuo"

Now, $0 contains 123456 but should be replace with 123556
123456 is a user entered number so it can be different on each computer so I can't use the Replace function.

How can I do this?

-BioDuo

Afrow UK 13th December 2005 14:53

code:
Function Replace3rdLetter
Exch $R0
Exch
Exch $R1
Exch
Exch 2
Exch $R2
Exch 2
Push $R3
StrCpy $R3 $R0 $R2
IntOp $R2 $R2 + 1
StrCpy $R0 $R0 "" $R2
StrCpy $R0 $R3$R1$R0
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!macro Replace3rdLetter RetVar ReplaceInStr ReplaceWithChar ReplaceAtIndex
Push "${ReplaceAtIndex}"
Push "${ReplaceWithChar}"
Push "${ReplaceInStr}"
Call Replace3rdLetter
Pop "${RetVar}"
!macroend
!define Replace3rdLetter '!insertmacro Replace3rdLetter'



Usage:
${Replace3rdLetter} $R0 "123456" "5" "4"
$R0 = 123556

Made this in college without a compiler so it is untested.
Also, you said you want the 3th (3rd) character replaced, but your example of 123456 > 123556 replaces the 4th character. The last parameter of ${Replace3rdLetter} specifies the index to replace; replacing it with the value of the 3rd parameter.

-Stu


All times are GMT. The time now is 17:56.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.