CFLib.org – Common Function Library Project

listCountListInList(lst1, lst2)

Last updated April 07, 2006

author

Trevor Orr

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Count the number of occurences of items from one list to another list.

Return Values:
Returns a number.

Example:

<cfset lst1 = "apples,organes,berries,star wars">
<cfset lst2 = "berries,coconuts,kameo">
<cfset cnt = ListCountListInList(lst1, lst2)>
<cfoutput>#cnt#</cfoutput>

Parameters:

Name Description Required
lst1 The first list. Yes
lst2 The second list. Yes

Full UDF Source:

/**
 * Count the number of occurences of items from one list to another list.
 * Missing var statement fixed by Raymond Camden.
 * 
 * @param lst1      The first list. (Required)
 * @param lst2      The second list. (Required)
 * @return Returns a number. 
 * @author Trevor Orr (fractorr@yahoo.com) 
 * @version 1, April 7, 2006 
 */
function listCountListInList(lst1, lst2) {
    var delim   = ",";
    var cnt     = 0;
    var pos     = 0;
    var item    = "";
    
    if (arrayLen(arguments) gt 2) delim = arguments[3];
        
    for(item=1; item LTE ListLen(lst2); item = item + 1) {
        pos = listFindNoCase(lst1, ListGetAt(lst2, item));
        if(pos) cnt = cnt + 1;
    }
    
    return cnt;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson