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