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

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