Archive: split string ?


split string ?
hi

i get a string from registry like
"name text number"
i used ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MySQL Servers and Clients 3.23.54" "UninstallString"

how can i split it ang get:
and get in $R0 "name" $R1 "text" $R2 "number" ??

please help thanks


Use StrCmp, StrCpy etc. You can find some string manipulation examples in the archive.


This function I wrote not long ago will do what you need:
http://nsis.sourceforge.net/archive/...instances=0,11

You just need to call it three times like so:


# Get "number"
Push 1 ; get text after 1st chunk from string end
Push 1 ; get 1 chunk before the 1st
Push "$R0" ; input string (in your case, read from registry)
Call AdvStrSort
Pop $R2
# $R2 will be the "number"

# Get "text"
Push 2 ; get text after 2nd chunk from string end
Push 1 ; get 1 chunk before the 2nd
Push "$R0" ; input string (in your case, read from registry)
Call AdvStrSort
Pop $R1
# $R1 will be the "text"

# Get "name"
Push 3 ; get text after 3rd chunk from string end
Push 1 ; get 1 chunk before the 3rd
Push "$R0" ; input string (in your case, read from registry)
Call AdvStrSort
Pop $R0
# $R0 will be the "name"


Hope that helps.
Remember to copy the function into your script too!

-Stu :)

thanks Afrow UK
it works but i dont know why :)
...
can you explain the function a littel bit
:) Exec exchanges the top elements of the stack ...


Hmm, this is a hard one to explain.
Plus, I'm rubbish at explaining stuff!

The best thing you can do, is to call it in a section, and put detailprints throughout the function, printing the different variables. If I want to see if something is working properly or not (searching for bugs), I do a DetailPrint OMG$0, or DetailPrint Hello!$1. The OMG or Hello bit shows me which DetailPrint is being printed, showing me the source of that variable.

-Stu


Maybe this page by VirtLink will help you understand the stack (Exch, Push, Pop) better:

http://nsis.sourceforge.net/archive/...instances=0,44


Also, once you learn how to use StrCpy fully, you are able to do a lot of things with it!

e.g.

StrCpy $R0 "Hello Jeff" 4 -4
$R0 = "Jeff"
StrCpy $R0 "Hello Jeff" 5 -10
$R0 = "Hello"
StrCpy $R0 "Hello Jeff" 1 -1
$R0 = "f" (last letter of Jef[f])
StrCpy $R0 "Hello Jeff" -2
$R0 = "Hello Je"
StrCpy $R0 "Hello Jeff" "" -2
$R0 = "ff"

Note: putting "" -2 (shown on the last example) is just like putting 2 -2

-Stu


dude.. ur link is not working..
http://nsis.sourceforge.net/archive...;instances=0,11
which has this AdvStrSort..


The NSIS Archive moved a long time ago.
http://nsis.sourceforge.net/Sort_String_2

-Stu


Archive links should still work. The specific instance of this specific page was removed. The page probably moved a category or removed from all categories.