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;
}

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