CFLib.org – Common Function Library Project

ListDeleteRange(list, from, to[, delimiter])

Last updated April 24, 2002

author

Shaun Ambrose

Version: 1 | Requires: CF5 | Library: StrLib

Description:
This function deletes a range of items from a list. If the ending position is greater than the length of the list, every item from the starting position until the end of the list is deleted. The range specified is inclusive.

Return Values:
Returns a string.

Example:

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

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

Returns:
d,e,f

Parameters:

Name Description Required
list The list to modify. Yes
from The position to begin deleting. Yes
to The position to stop deleting. Yes
delimiter The delimiter to use. Defaults to a comma. No

Full UDF Source:

/**
 * This function deletes a range of items from a list.
 * 
 * @param list      The list to modify. 
 * @param from      The position to begin deleting. 
 * @param to      The position to stop deleting.  
 * @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 ListDeleteRange(list, from, to) {
    var delimiter = ",";
    var i = from;
        
    if(arrayLen(arguments) gt 3) {
        delimiter = arguments[4];
    }
    
    if(to gt listLen(list,delimiter)) to = listLen(delimiter);
    
    for(; i lte to; i=i+1) {    
        list=listDeleteAt(list, from, 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