CFLib.org – Common Function Library Project

ListgetMultipleOf(list, factorOf[, delim])

Last updated March 06, 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;
}

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