Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Replace ampersand in URL

Participant ,
Mar 24, 2010 Mar 24, 2010

How do I replace an ampersand (&) in my string with the word ' and '

How do I make?

Mike&Pat

into

MikeandPat

2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 24, 2010 Mar 24, 2010

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

Translate
LEGEND ,
Mar 24, 2010 Mar 24, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 24, 2010 Mar 24, 2010

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')#>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 24, 2010 Mar 24, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources