CFLib.org – Common Function Library Project

ListDeleteMid(list, startPos, numElements[, delimiter])

Last updated April 24, 2002

author

Shaun Ambrose

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Deletes n elements starting at the specified start position. Accepts an optional delimiter. Note that if the number of items to delete at startPos is greater than the length of the list, the function will remove delete all items from startPos onward.

Return Values:
Returns a string.

Example:

<cfset list="a,b,c,d,e,f,g">

<cfoutput>
#ListDeleteMid(list, 3, 1)#
</cfoutput>

Parameters:

Name Description Required
list The list to modify. Yes
startPos The starting position. Yes
numElements Number of items to delete, including item at startPos. Yes
delimiter The delimiter to use. Defaults to a comma. No

Full UDF Source:

/**
 * Deletes n elements starting at the specified start position.
 * Modified by RCamden
 * 
 * @param list 	 The list to modify. 
 * @param startPos 	 The starting position. 
 * @param numElements 	 Number of items to delete, including item at startPos. 
 * @param delimiter 	 The delimiter to use. Defaults to a comma. 
 * @return Returns a string. 
 * @author Shaun Ambrose (shaun.ambrose@arcorsys.com) 
 * @version 1, April 24, 2002 
 */
function ListDeleteMid(list, startPos, numElements) {
	var i=0;
	var delimiter=",";
	var finish=startPos+numElements-1;

	if (Arraylen(arguments) gt 3) {
		delimiter=arguments[4];
	}
	if (finish gt ListLen(list, delimiter)) {
    	finish = listLen(list,delimiter);
  	}
	for (i=startPos; i lte finish; i=i+1) {
		list=listDeleteAt(list, startpos, delimiter);
	}
	return list;
}
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