|
enema Beginner
Joined: 06 Aug 2009 Posts: 11
|
Posted: 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. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
enema Beginner
Joined: 06 Aug 2009 Posts: 11
|
Posted: 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. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: Mon Sep 14, 2009 12:50 pm |
Change Matt's to use this:
#IF (%match(%i, %j)) |
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|