We help IT Professionals succeed at work.

creating a new list

nmarano
nmarano asked
on
Experts-

I am trying to create a new list and am looking for some help.


          <cfset mycorrectList = '1,2,3,4,5,6,7,8,9,10'>
      <cfset mystudentList = '1,2,3,4,10'>
   
          <cfif listfind(mystudentList,mycorrectList)>
       .....Here I want to be able to delete the element if it is found and create a new list that would look like this..

<cfset mynewestList = '5,6,7,8,9'>

Can I use listDeleteAt?  Not knowing where the element is located in my list doesn't allow me to use this does it?  Any help would be appreciated

Thanks
Nick

              
Comment
Watch Question

CERTIFIED EXPERT
Commented:
listFind() actually returns the position of the element on the list, so you could use it by this format:

 <cfset pos = listFind(....)>

and then delete at the position

It may be an easier way to build a new list..

<cfset newList = "">
<cfloop index="theValue" list="#myCorrectList#">
    <cfif listFind(myStudentList, theValue) eq 0>
        <cfset newList = listAppend(newList, theValue)>
    </cfif>
</cfloop>

The above addresses this request - let me know if I got it wrong...

   I want a list of values thare are in myCorrectList, but not in myStudentList



Author

Commented:
Thanks I'll try that out

Author

Commented:
Thanks!  I had it set similar except I was missing the eq 0
<cfloop index="i" list="#myCorrectList#">
    <cfif listFind(myStudentList, i)><!--- was missing eq 0 here --->
        <cfset newList = listAppend(newList, i)>
    </cfif>
</cfloop>

Explore More ContentExplore courses, solutions, and other research materials related to this topic.