- Reverse()
- Find()
- Quick Rules for Using CFScript
- FindNoCase()
- REReplace
- ReplaceList()
ReplaceList()
The purpose of the ReplaceList() function is to return string with all occurrences of specified characters in one comma-separated list of characters with characters from another comma-separated list. It has the following structure:
ReplaceList(string, list1, list2)
NOTE
Unlike other replacement functions, ReplaceList() will replace all occurrences of a listed character; you do not have the option to specify a narrower scope.
Let's write our replace list to account for characters typically used in sentences because that's what we are most likely to have to deal with. Our second list should be an empty string. Here's the function:
MyString=ReplaceList(form.MyString, "?,',"",:,.,!, ", "");
There are three items here: The first is form.MyString, which is the variable we want to replace special characters for. The second item is a comma-separated list, in double quotes, that begins with a ? and ends with a space. This is the list of characters to look for in the variable form.MyString. Notice that one item is "". We have to escape the double quote marks, or ColdFusion thinks that you are ending the list. The third item is a list that simply contains an empty string: "".
I think we have a winner.
My new book, Core ColdFusion 5, gives you the nitty-gritty on all the aspects of ColdFusion development you need to succeed. It contains a wealth of complete applications, including a site search, a rotating banner ad application, and much more information on creating user-defined functions. Pick up a copy today to find out more.