Skip to main content
Inspiring
November 26, 2014
Question

replace quotes?

  • November 26, 2014
  • 1 reply
  • 1631 views

Hello I'm on Coldfusion 10 and I'm trying to figure out how to replace quotes ("). So far I tried this:

<cfset Session.Artist1 = Replace(Session.Artist1,"&quot;","&quot;",'ALL') >

That does nothing, I then tried this:

<cfset Session.Artist1 = Replace(Session.Artist1,"&#34","&quot;",'ALL') >

That errors out CF. I'll get this:

Error Occurred While Processing Request

Invalid construct: Either argument or name is missing.

So is there anything that would work in CF and in SQL for " (quotes)? I having people use the HTML &quot;, but that also shows up in SQL as the coding. I would like it to work in CF and in SQL as just ", but can't figure out how. Any help would be great.

Thanks

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
November 26, 2014

Chr(34) is neat for the double quote. So try

<cfset Session.Artist1 = Replace(Session.Artist1, chr(34), "&quot;", "all") >

You could also be creative with single quotes, like this

<cfset Session.Artist1 = Replace(Session.Artist1, '"', '&quot;', 'all') >

taunntAuthor
Inspiring
November 26, 2014

I tried this and it doesn't do anything:

<cfset Session.Artist1 = Replace(Session.Artist1 , Chr(34),"&quot;",'ALL') >

What is happening is you can search for 'the "thing"' after you hit return CF will change it to 'the'. So it will ignore any characters after the ".

BKBK
Community Expert
Community Expert
November 27, 2014

I get no such complication. When I run the code

<cfset str='the "thing"'>

<cfset newStr = replace(str, chr(34),"&quot;","all")>

<cfoutput>#newStr#</cfoutput>

I get the result

the &quot;thing&quot;

Remember to view the result in the browser's source page.