CFLib.org – Common Function Library Project

splitList(orgList[, listDel])

Last updated August 1, 2006

author

Tom Kitta

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Splits list into two lists of about equal list length. Returns a structure with two new lists. Only about half of the original list is looked at in order to increase UDF's speed.

Return Values:
Returns a sturct.

Example:

<cfdump var="#splitList("")#"><!--- Returns two empty strings --->
<cfdump var="#splitList("1")#"><!--- Returns 1 and empty string --->
<cfdump var="#splitList("1,2,3")#"><!--- Returns 1,2, and 3 --->
<cfdump var="#splitList("1,,2,,,3,4,123")#"><!--- Returns 1,,2,,,3, (valid list with 3 elements) and 4,123 --->

<cfdump var="#splitList("1@2@3@4", "@")#">

Parameters:

Name Description Required
orgList Original list. Yes
listDel List delimeter. Defaults to a comma. No

Full UDF Source:

/**
 * Split list into two lists of about equal length.
 * RCamden added variable delim and clean up of trailing delim
 * 
 * @param orgList 	 Original list. (Required)
 * @param listDel 	 List delimeter. Defaults to a comma. (Optional)
 * @return Returns a sturct. 
 * @author Tom Kitta (tom@tomkitta.com) 
 * @version 2, August 1, 2006 
 */
function splitList(orgList) {
	var ret = structNew();
	var listDel = ",";
	var i = 0;
	var listLen = "";
	var midPoint = "";
	
	if(arrayLen(arguments) gte 2) listDel = arguments[2];
	
	listLength = listLen(orgList,listDel);
	midPoint = round(listLength/2);

	ret.part1 = "";
	ret.part2 = orgList;

	for (i=1;i lte midPoint;i=i+1) ret.part2 = ListDeleteAt(ret.part2,1, listDel);
	if (listLength gt 0) ret.part1 = left(arguments.orgList,len(arguments.orgList) - Len(ret.part2));
	
	if(right(ret.part1,1) is listDel) ret.part1 = left(ret.part1, len(ret.part1)-1);
	return ret;
}
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