CFLib.org – Common Function Library Project

ListgetMultipleOf(list, factorOf[, delim])

Last updated March 6, 2003

author

Sudhir Duddella

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns a list with a specified factor of list elements from the passed list. Special delimeters (non-comma) can be specified in the optional final argument.

Return Values:
Returns a string.

Example:

<cfset List = "1,2,3,4,5,6,7,8,9,10">
<cfoutput>#ListgetMultipleOf(List,3)#</cfoutput>

Parameters:

Name Description Required
list List to parse. Yes
factorOf Specifies how many items to skip before getting an item. Yes
delim List delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Returns a list with a specified factor of list elements from the passed list .
 * 
 * @param list 	 List to parse. (Required)
 * @param factorOf 	 Specifies how many items to skip before getting an item. (Required)
 * @param delim 	 List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Sudhir Duddella (skduddella@hotmail.com) 
 * @version 1, March 6, 2003 
 */
function ListgetMultipleOf(List,factorOf){
	var delim = ",";
	var result = "";
	var i = 1;
	
	if (factorOf lte 0) return result;
	if (ArrayLen(arguments) gt 2) delim = arguments[3];
			
	for (i=1;i lte ListLen(List,delim); i = i+1) {
		if (i mod factorOf eq 0) result = ListAppend(result,ListGetAt(List,i,delim),delim);
	}
		
	return result;
}
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