|
|
|
item
Syntax: %item(list, n)
returns the nth item of the given stringlist.
As of version 2.06, this function can also be used to retrieve the nth value in a database variable (to return the nth key, see %dbkey).
Example:
#SHOW %item("Athos|Bertrand|Caesar",3)
displays: Caesar |
User comments |
Tech: Tue Aug 21, 2007 9:14 pm |
|
[Edit] Just adding some additional notes based on this thread.
The %item function does not autowrap like the #CASE does. If you have an n larger than the number of items in the list, the function will return a null value for those items.
This code snippet
Code: |
#loop 4 {#show %i : %item("one|two",%i)} |
will output
Code: |
1 : one
2 : two
3 :
4 : |
If you do want it to do a "wrap-around" then a command similar to following should do the trick.
Code: |
#loop 4 {#show %i : %item("one|two",((%i-1) \ 2)+1)} |
|
|
|
Arminas: Wed Aug 22, 2007 1:58 am |
|
Thank you Tech.
Quote: |
#loop 4 {#show %i : %item("one|two",((%i-1) \ 2)+1)} |
The blue 2 is the number of items in the list so.
For a list with more items you would want to make the appropriate change.
Quote: |
#loop 4 {#show %i : %item("one|two|three",((%i-1) \ 3)+1)} |
If you did not know how many items were in the list because you were using a variable list you could do this.
Quote: |
#loop 4 {#show %i : %item(@list,((%i-1) \ %numitems(@list))+1)} |
|
|
|
|