Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
enema
Beginner


Joined: 06 Aug 2009
Posts: 11

PostPosted: Mon Sep 14, 2009 2:02 am   

Comparing string lists
 
I have 2 string lists to compare, assume they are as follows:

#VAR colourCheck= {red|black}
#VAR colours= {red|blue|orange|red|orange|green|black|red}

I would like the resulting string list to read:

#VAR colourFound= {red|red|red|black}



Essentially I would like to check the first value in <colourCheck> sequentially against every value in <colours>, then the second value and so on. I am using %additem so i can repeat instances of the same word in the resulting list.

Thanks in advance for the help.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Sep 14, 2009 2:09 am   
 
Code:

#forall @colours {
  #forall @colourcheck {
    #if (%i = %j) {Colourfound = %additem(%i,@ColourFound)}
  }
}


Essentially, because of the duplicates you have to step through each element.
_________________
EDIT: I didn't like my old signature
Reply with quote
enema
Beginner


Joined: 06 Aug 2009
Posts: 11

PostPosted: Mon Sep 14, 2009 2:37 am   
 
Damn I just worked it out and came on here to say sorry to bother. Thanks for the fast reply :)

I'm using:

#FORALL @colours{
#IF (%ismember ( %i, @colourCheck)) {
#VAR colourFound %additem( %i, @colourFound)
}
}

It seems to work. Is there a problem I'm not seeing?


P.S. I have a second problem, what if one of the elements in @colours was "reallyreallyred" but I still wanted it to return "red" to @colourFound. It doesn't work because they don't match exactly, but I'm not sure how to use wildcards outside of the %i and %j variables in this syntax.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Mon Sep 14, 2009 12:50 pm   
 
Change Matt's to use this:

#IF (%match(%i, %j))
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net