CFLib.org – Common Function Library Project

listCountListInList(lst1, lst2)

Last updated April 7, 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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson