Description
Replaces occurrences of the elements from a delimited list in a string with corresponding elements from another delimited list. The search is case sensitive.
Returns
A copy of the string, after making replacements.
Category
List functions, String functions
Function syntax
ReplaceList(string, list1, list2,includeEmptyFields) ReplaceList(string, list1, list2, delimiter, includeEmptyFields) ReplaceList(string, list1, list2, delimiter_list1, delimiter_list2, includeEmptyFields)
See also
Find, REFind, Replace, REReplace
Parameters
Parameter |
Description |
---|---|
string |
A string, or a variable that contains one, within which to replace substring |
list1 |
Comma-delimited list of substrings for which to search |
list2 |
Comma-delimited list of replacement substrings |
delimiter |
Common delimiter for both search and replacement. |
delimiter_list1 |
Delimiter for search. |
delimiter_list2 |
Delimiter for replacement. |
includeEmptyFields |
When true, empty list elements are preserved. |
Usage
The list of substrings to replace is processed sequentially. If a list1 element is contained in list2 elements, recursive replacement might occur. The second example shows this.
Example
Example with delimiter to both the lists
<cfscript> stringtoreplace = "The quick brown fox jumped over the lazy dog." writeOutput(ReplaceList(stringtoreplace,"dog:brown:fox:black", "cow:black:ferret:white", ":")) </cfscript>
This example returns the following string:
The quick white ferret jumped over the lazy cow.
Example with delimiter specific to individual lists
<cfscript> stringtoreplace = "The quick brown fox jumped over the lazy dog." writeOutput(ReplaceList(stringtoreplace,"dog:brown:fox:black", "cow-black-ferret-white", ":" , "-")) </cfscript>
This example returns the following string:
The quick white ferret jumped over the lazy cow.
Example with includeEmptyFields = true
<cfscript> stringtoreplace = "The quick brown fox jumped over the lazy dog." writeOutput(ReplaceList(stringtoreplace, "dog:brown:fox:black", "--black-ferret-white", ":", "-", true)) </cfscript>
This example returns the following string:
The quick ferret jumped over the lazy .
Example with includeEmptyFields = false
<cfscript> stringtoreplace = "The quick brown fox jumped over the lazy dog." writeOutput(ReplaceList(stringtoreplace, "dog:brown:fox:black", "--black-ferret-white", ":", "-", false)) </cfscript>
This example returns the following string:
The quick ferret white jumped over the lazy .