Utility Function: ListRemoveDuplicates()

I often use lists behind the scenes, and if I'm looping through and processing stuff, I had to reprocess something if its been duplicated in the list.

<cffunction name="ListRemoveDuplicates" access="public" returntype="string" output="false">
    <cfargument name="lsList" type="string" required="false" default="">
    <cfargument name="delimiters" type="string" required="false" default=",">

    <cfset var lsNewList = "">

    <cfloop list="#arguments.lsList#" index="listItem" delimiters="#arguments.delimiters#">
        <cfif NOT listFind(lsNewList, listItem, arguments.delimiters)>
            <cfset lsNewList = listAppend(lsNewList, listItem, arguments.delimiters)>

    <cfreturn lsNewList>

This should probably be ListRemoveDups() as is more fitting for CF, but I prefer the longer name


Related Blog Entries


Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me.

Post a job. Find one. authenticjobs.com

Interested in becoming a sponsor? Contact me.