Old 13th December 2005, 08:07   #1
BioDuo
Junior Member
 
Join Date: Jun 2005
Posts: 21
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
BioDuo is offline   Reply With Quote
Old 13th December 2005, 14:53   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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

Last edited by Afrow UK; 13th December 2005 at 16:32.
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump