|
thd Beginner
Joined: 04 Mar 2005 Posts: 10
|
Posted: Fri Mar 04, 2005 7:48 pm
How to return parts of string list in a variable |
#var example {aa|bb|cc|dd|ee|ff|gg}
I want to
1. return the first 3 strings in @example and define them into a new variable @new, that is, new will be difined as {aa|bb|cc};
2. return the last 4 strings in @example and define them into a new variable @new, that is, new will be difined as {dd|ee|ff|gg};
3. return the second to the fifth into @new, that is, new will be difined as {bb|cc|dd|ee}.
How to do this ? |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Fri Mar 04, 2005 8:02 pm |
#loop 3 {#var new %additem(%item(@example,%i),@new)}
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
thd Beginner
Joined: 04 Mar 2005 Posts: 10
|
Posted: Fri Mar 04, 2005 8:11 pm |
Thanks !
And how about the 2nd and 3rd questions ? |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Fri Mar 04, 2005 8:48 pm |
"Teach a man to fish..."
Your remaining questions are variations of the first.
read the help files for the commands and functions I used
#loop
%additem
%item
I'll show you how to do #3 but then #2 is all yours, since they're similar
you'll have I think enough examples to do one solo.
Code: |
#loop 2,5 {#var new %additem(%item(@example,%i),@new)} |
#loop 2,5 tells zmud to start at number two and loop until 5
each time it loops the commands {#var new %additem(%item(@example,%i),@new)}
are executed with %i being replaced by the number of the iteration ie
%i = 2....%i = 5
we use this value to return the ith value from the example list using the %item command and naturally %additem adds this to @new list and a new list is return this updated list is assigned to the @new list.
goodluck |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
thd Beginner
Joined: 04 Mar 2005 Posts: 10
|
Posted: Fri Mar 04, 2005 9:26 pm |
thanks a lot!
I'll try to learn how to fish by myself, and your guide will promote my learning speed. :) |
|
|
|
|
|