Utility Function: ListRemoveDuplicates()
- October 25, 2008 5:29 AM
- ColdFusion, Utility Function
- Comments (0)
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)>
</cfif>
</cfloop>
<cfreturn lsNewList>
</cffunction>
This should probably be ListRemoveDups() as is more fitting for CF, but I prefer the longer name