Name

ListValueCount — New as of ColdFusion 4.01

Synopsis

ListValueCount(list, value [, delimiters])

Counts the number of times value appears in the specified list. The search performed is case-sensitive. An optional delimiter can be specified if the list is delimited with a character other than the comma (the default). The following example counts the number of times each unique value appears in the list and outputs the results for each item:

<CFSET MyList = "Apple,orange,apple,Orange,Peach,pear,apple,pear,peach,Pear,
Apple,Peach,orange,apple">
<CFSET UniqueList = "">

<CFLOOP INDEX="Element" LIST="#MyList#">
  <CFIF ListFind(UniqueList, Element) IS "No">
    <CFSET UniqueList = ListAppend(UniqueList, Element)>
  </CFIF>
</CFLOOP>

<CFOUTPUT><B>Original List:</B> #MyList#</CFOUTPUT>
<P><CFLOOP INDEX="Element" LIST="#UniqueList#">
  <CFOUTPUT>
    #Element# appears: #ListValueCount(MyList, Element)# times.<BR>
  </CFOUTPUT>
</CFLOOP>

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.