Returns string with occurrences of the elements from a specified comma-delimited list replaced with corresponding elements from another comma-delimited list. The search is case-sensitive.
ReplaceList(string, list1, list2)
Find,
REFind,
Replace,
REReplace
Parameter |
Description |
---|---|
string |
A string |
list1 |
Comma-delimited list of substrings to replace |
list2 |
Comma-delimited list of replace substrings |
The list of substrings to be replaced is processed sequentially. There may be recursive replacement if a list1 element is contained in list2 elements. The second example demonstrates this.
<!--- 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") 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>