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-sensitive.
ReplaceList(string, list1, list2)
Any string.
Comma-delimited list of substrings to be replaced.
Comma-delimited list of replace substrings.
Note that the list of substrings to be replaced is processed one after another. In this way you may experience recursive replacement if one of your list1 elements is contained in list2 elements. The second example listed below demonstrates such replacement.
<!--- This example shows the use of Replacelist ---> <HTML> <HEAD> <TITLE> Replacelist Example </TITLE> </HEAD> <BODY bgcolor=silver> <H3>Replacelist Example</H3> <P>The Replacelist function returns <I>string</I> with <I>substringlist1</I> (e.g. "a,b") being replaced by <I>substringlist2 </I> (e.g. "c,d") in the specified scope. <CFIF IsDefined("FORM.MyString")> <P>Your original string, <CFOUTPUT>#FORM.MyString#</CFOUTPUT> <P>You wanted to replace the substring <CFOUTPUT>#FORM.MySubstring1# </CFOUTPUT> with the substring <CFOUTPUT>#FORM.MySubstring2#</CFOUTPUT>. <P>The result: <CFOUTPUT>#Replacelist(FORM.myString, FORM.MySubstring1, FORM.mySubString2)#</CFOUTPUT> </CFIF> <FORM ACTION="replacelist.cfm" METHOD="POST"> <P>String 1 <BR><INPUT TYPE="Text" VALUE="My Test String" NAME="MyString"> <P>Substring 1 (find this list of substrings) <BR><INPUT TYPE="Text" VALUE="Test, String" NAME="MySubstring1"> <P>Substring 2 (replace with this list of substrings) <BR><INPUT TYPE="Text" VALUE="Replaced, Sentence" NAME="MySubstring2"> <P><INPUT TYPE="Submit" VALUE="Replace and display" NAME=""> </FORM> </BODY> </HTML>