CFLib.org – Common Function Library Project

listDelete(variable[, qs])

Last updated May 17, 2006

author

Alessandro Chisari

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Delete items from a list. Will find and remove specified items from a list. Based on QueryStringDeleteVar UDF.

Return Values:
Returns a string.

Example:

<cfoutput>#listdelete("id,name","id,name,foo,moo")#</cfoutput>

Parameters:

Name Description Required
variable An item, or a list of items, to remove from the list. Yes
qs The actual list to parse. Can be blank. No

Full UDF Source:

/**
 * Delete items from a list.
 * 
 * @param variable      An item, or a list of items, to remove from the list. (Required)
 * @param qs      The actual list to parse. Can be blank. (Optional)
 * @return Returns a string. 
 * @author Alessandro Chisari (ruchizzy@hotmail.com) 
 * @version 1, May 17, 2006 
 */
function listdelete(variable){
        //var to hold the final string
        var string = "";
        //vars for use in the loop, so we don't have to evaluate lists and arrays more than once
        var ii = 1;
        var thisVar = "";
        var thisIndex = "";
        var array = "";
        var qs = "";
        if(arrayLen(arguments) GT 1)
                qs = arguments[2];
        //put the query string into an array for easier looping
        array = listToArray(qs,",");            
        //now, loop over the array and rebuild the string
        for(ii = 1; ii lte arrayLen(array); ii = ii + 1){
                thisIndex = array[ii];
                thisVar = thisIndex;
                //if this is the var, edit it to the value, otherwise, just append
                if(not listFindnocase(variable,thisVar))
                        string = listAppend(string,thisIndex,",");
        }
        //return the string
        return string;
}

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