Link to home
Create AccountLog in
Avatar of NYGiantsFan
NYGiantsFanFlag for United States of America

asked on

comparing two lists in coldfusion

Hi,

I have two lists in coldfusion. I want to see if list one have the values of list two, if so, I want them removed.

How do I do?

thanks.
SOLUTION
Avatar of Andrew Maurer
Andrew Maurer
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Avatar of Tomarse111
Tomarse111
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of lhp2000
lhp2000

<cfset List1="1,2,3,4,5,6,7,8,9">
<cfset List2="1,10,11,12,1,4">
<cfset List3  "">
<cfloop list="#List1#" index="l_key">
       <cfif not ListContainsNoCase(List2,key)>      
              <cfset List3=ListAppend(List3,key)>
       </cfif>
</cfloop>
<cfdump var="#List3#">
hey lhp2000... thats another take on it ;)  creating a new list..
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I guess I should have tested it BEFORE posting :)

This one actually works..
<!--- returns all elements of list one minus the elements of list two --->
<!--- #listMinus("1,2,3,3,3,4,5", "3,5,6")#  returns 1,2,4 --->
<cffunction name="listMinus" access="public" output="false">
   <cfargument name="listOne"  required="true" default="" />
   <cfargument name="ListTwo"  required="false" default="" />
 
   <cfset var result = "">
   <cfset var kk = "">
    
   <cfloop index="kk" list="#arguments.listOne#">
     <cfif listFindNoCase(arguments.listTwo,kk) eq 0>
       <cfset result = listAppend(result,kk)>
     </cfif>
   </cfloop>
    
   <cfreturn result>
</cffunction>
 
 
<cfoutput>#listMinus("1,2,3,3,3,4,5", "3,5,6")#</cfoutput>

Open in new window

@NYGiantsFan ?  ping...
timeout... tahahha
Avatar of NYGiantsFan

ASKER

Thanks, although I figured it out on my own.  Thanks all.