Copy link to clipboard
Copied
How do I replace an ampersand (&) in my string with the word ' and '
How do I make?
Mike&Pat
into
MikeandPat
A good thing to do when you find yourself asking "how do I do x in CF" is to have a look at the docs: they're pretty thorough.
If you go to the docs and search on "replace", the replace() function is the first match:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f42.html
--
Adam
Copy link to clipboard
Copied
A good thing to do when you find yourself asking "how do I do x in CF" is to have a look at the docs: they're pretty thorough.
If you go to the docs and search on "replace", the replace() function is the first match:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f42.html
--
Adam
Copy link to clipboard
Copied
Like this
city is the original string to replace the & with 'and'.
<CFSET city1= #Replace(form.city,&,and)#>
OR with quotes
<CFSET city1= #Replace(form.city,'&','and')#>
Copy link to clipboard
Copied
The best way to find out these things is to try it! One of those will simply error. The other should work.
Also: the pound signs are not needed there at all.
Can I recommend you further your reading of the docs with these bits:
Pound signs:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7fc3.html (including all the linked pages at the bottom)
Strings:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec09af4-7fd1.html
Really, I think you could benefit from (re?)reading all of the first three sections of "The CFML Programming Language":
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WS8f0cc78011fffa71866534d11cdad96e4e-8000.html
And having a breeze over the whole CFML tag & function references would not hurt:
Tags:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec17576-7ffe.html
Functions:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ff8.html
Don't try to remember the whole lot, just get a feel for what CFML can do, so next time you have a question like this, you'll find yourself thinking "yeah... I seem to recall CFML can do something like that..." and it'll be a good place to start your investigations.
--
Adam
Find more inspiration, events, and resources on the new Adobe Community
Explore Now