|
Vaxon Newbie
Joined: 04 Jan 2010 Posts: 5
|
Posted: Sun May 26, 2013 3:05 pm
Getting items from the string list |
Greetings,
I'm wondering if there is a possibility to get all occurrences (in case where there are more than one in string list) of an item from the string list returning it's number in the list (something like %ismember but to return more items)?
Eg.
$string = a|b|c|d|a|e|f|a|a
%ismember(a,$string) will return only one item (1 to be exact) ignoring rest (so 5, 8 and 9). Anyone know how to return all of them? Thanks in advance.
Regards,
V. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sun May 26, 2013 4:11 pm |
#LOCAL $place $list
#FORALL $string {$place=($place+1);#IF (%i=a) {#ADDITEM $list %i}}
#SAY $list |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Vaxon Newbie
Joined: 04 Jan 2010 Posts: 5
|
Posted: Sun May 26, 2013 4:27 pm |
This unfortunately does not work (still returns only first occurrence).
I think I explained my issue incorrectly.
I've got string list @allM with names of known players, @alloM with short description of those (in the same order so eg. fifth item in @allM is correlated to fifth item in @alloM). As none of those are unique duplicates can be found in both of those string lists. What I need:
Example:
@allM = John|Steve|Paul|Roderick
@alloM = short fat dwarf|big stubborn elf|short fat dwarf|little big man
Pattern:
Short fat dwarf.
What I want to see:
Short fat dwarf (John, Paul).
Hope it's clearer now.
PS. Got it working - just needed to replace last %i with %item(@list,$place). |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sun May 26, 2013 6:38 pm |
Sorry bout that, i had just woken up.
#FORALL $string {$place=($place+1);#IF (%i=a) {#ADDITEM $list $place}}
was how i meant it to be, then $list contains all the %item numbers it occurs at
but if you got it working for you, great |
|
_________________ Discord: Shalimarwildcat |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Mon May 27, 2013 2:55 am |
Vaxon why not just create a data record instead of parallel lists (arrays)?
Example:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<var name="allMembers" type="Record" copy="yes">
<value>John=short fat dwarf|Steve=big stubborn elf|Paul=short fat dwarf|Roderick=little big man</value>
<json>{"Roderick":"little big man","Paul":"short fat dwarf","John":"short fat dwarf","Steve":"big stubborn elf"}</json>
</var>
<alias name="FindDesc" copy="yes">
<value>#local $list
$value = %trim(%params)
#loopdb @allMembers
{
#if ($value == %val)
{
#additem $list %key
}
}
#print {$value [%expandlist($list,", ")]}</value>
</alias>
</cmud>
|
Entering "FindDesc short fat dwarf" returns the following:
short fat dwarf [John, Paul] |
|
|
|
|
|