Hi Les,

I have a little function for doing this:
<cffunction name="listCleanup" returntype="string" access="public" 
hint="removes duplicates from given list and returns it alphanumerical sorted">
    <cfargument name="lList" type="string" required="yes" hint="list to clear 
up">
    <cfargument name="bSort" type="Boolean" required="no" default="FALSE" 
hint="whether to return sorted list or not">

    <cfset var lReturn         = "">
    <cfset var strExistingKeys = structNew()>
    <cfset var aReturnList     = arrayNew(1)>

    <cfloop list="#arguments.lList#" index="sElement">
      <cfif NOT structKeyExists(strExistingKeys,sElement)>
        <cfset arrayAppend(aReturnList,sElement)>
        <cfset strExistingKeys[sElement] = TRUE>
      </cfif>
    </cfloop>

    <cfif arguments.bSort>
      <cfset arraySort(aReturnList,"textNoCase")>
    </cfif>
    <cfset lReturn = arrayToList(aReturnList)>

    <CFRETURN lReturn>
  </cffunction>

Greets,
Sigi

>What's the easiest way to remove dupes from a value list?
>
>I want to turn, say, this:
>History,Recreation,History,Music,Architecture,History,Recreation,Music
>
>into this:
>History,Recreation,Music,Architecture
>
>Thanks in advance for your help,
>Les 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343620
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to