CFLib.org – Common Function Library Project

ReplaceListNoCase(str, list1, list2)

Last updated December 11, 2001

author

Matthew Walker

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Returns string with all occurrences of the elements from the specified comma-delimited list being replaced with their corresponding elements from another comma-delimited list. The search is case-insensitive. If an item does not appear in the second list, the item from the first list is replaced with an empty string. Chr(31) is used to mark empty elements, so if there is the possibility of a string containing (and needing) this character, the function should not be used as is.

Return Values:
Returns a modified list.

Example:

<cfset orig = "It's too soon to say">
<cfoutput>
original list: #orig#<br>
modified list: #ReplaceListNoCase(orig, "it's,soon,say", "early,tell")#
</cfoutput>

Parameters:

Name Description Required
str The string to modify. Yes
list1 The list of terms to search for. Yes
list2 The list of corresponding items to use as replacements. Yes

Full UDF Source:

/**
 * Replace all occurences of elements in list one with elements in list two. Case insensitive version of ReplaceList.
 * Modified by Raymond Camden
 * 
 * @param str 	 The string to modify. 
 * @param list1 	 The list of terms to search for. 
 * @param list2 	 The list of corresponding items to use as replacements. 
 * @return Returns a modified list. 
 * @author Matthew Walker (matthew@electricsheep.co.nz) 
 * @version 2, December 11, 2001 
 */
function ReplaceListNoCase(str,list1,list2) {
	var i = 1;
	var newval = "";
	for(; i lte listLen(list1); i=i+1) {
		if(i gt listLen(list2)) newval = "";
		else newval = listGetAt(list2,i);
		str = ReplaceNoCase(str,listGetAt(list1,i),newval,"all");		
	}
	return str;
}
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