CFLib.org – Common Function Library Project

ListRemoveByString(list, str[, mode][, delim])

Last updated June 21, 2002

author

Markus Schneebeli

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Removes list values which contain the string provided when mode is true (default). Removes list values which don't contain the string provided when mode is false.

Return Values:
Returns a string.

Example:

<cfset list = "TestLib, CustomLib, Demo, New">
<cfoutput>
Before: #list#<br>
After: #ListRemoveByString(list, "Lib")#<br>
</cfoutput>

Parameters:

Name Description Required
list The list to modify. Yes
str The string to look for. Yes
mode If true, removes matches. If false, keeps matches. The default is true. No
delim The delimiter to use. Default is comma. No

Full UDF Source:

/**
 * Removes values from a list by string pattern.
 * Mods by RCamden
 * 
 * @param list      The list to modify. (Required)
 * @param str      The string to look for. (Required)
 * @param mode      If true, removes matches. If false, keeps matches. The default is true. (Optional)
 * @param delim      The delimiter to use. Default is comma. (Optional)
 * @return Returns a string. 
 * @author Markus Schneebeli (markus.schneebeli@inm.ch) 
 * @version 2, June 21, 2002 
 */
function ListRemoveByString(list, str) {
    var i = listLen(list);
    var mode = true;
    var delim = ",";
    
    if(arrayLen(arguments) gte 3) mode = arguments[3];
    if(arrayLen(arguments) gte 4) delim = arguments[4];
    
    for (i=ListLen(list, delim); i gte 1 ; i=i-1) {
        if(  (mode and findNoCase(str,listGetAt(list,i,delim))) or (not mode and not findNoCase(str,listGetAt(list,i,delim)))) list = listDeleteAt(list,i,delim);
    }
    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