Skip to main content
Inspiring
September 20, 2011
Answered

Use ReReplace with Evaulate

  • September 20, 2011
  • 2 replies
  • 727 views

Hi,

      I have a page that I am passing the letter "X" through a hidden field to my action page. But when I try to output the "X", it put the single quotes around the X like this 'X'. How can I remove the single quotes from displaying on the page? I was thinking using the ReReplace function, but I'm not sure how to write this code with the Evaluate function. Here's what I have:

<cfif isDefined("form.Comments#id#") and #Evaluate("form.Comments#id#")# neq "">

    <font size = "5" color=dd0000><strong>#Evaluate("form.Flag_Comments#id#")#</strong></font>

    <cfelseif "form.Comments#id#" eq "">

     

    </cfif>

How can I incorporate this with the Evaluate function above:

#ReReplace(cookie.class, "\'", "", "ALL")#

I think this will remove the single quotes, correct? Thanks.

Andy

    This topic has been closed for replies.
    Correct answer JMF3

    I don't see anything called cookie.class in your sample code, so not sure

    what you're trying to strip single quotes out of, but think of your form

    structure as a structure and don't use Evaluate() at all:

    #form["Flag_Comments#id#"]#

    If you just want single quotes out of your form test, you don't need RegEx

    for that:

    <cfif structKeyExists(form, "Comments#id#") and

    replace(form["Comments#id#"], "'", "", "all") neq ""

    2 replies

    Inspiring
    September 20, 2011

    JMF,

         Thank you. I was not able to get the structKeyExists to work, but I was able to get it to work this way:

    <cfif isDefined("form.Comments#id#") and #Evaluate("form.Comments#id#")# neq "">

        <font size = "5" color=dd0000><strong>

           #Replace(form["Flag_Comments#id#"], "'", "", "all")#

        </strong></font>

        <cfelseif "form.Comments#id#" eq "">

         

        </cfif>

    The cookie above was just an example of what I had somewhere else of how to not display the single quotes on the page. Thanks again!

    Andy

    JMF3Correct answer
    Participating Frequently
    September 20, 2011

    I don't see anything called cookie.class in your sample code, so not sure

    what you're trying to strip single quotes out of, but think of your form

    structure as a structure and don't use Evaluate() at all:

    #form["Flag_Comments#id#"]#

    If you just want single quotes out of your form test, you don't need RegEx

    for that:

    <cfif structKeyExists(form, "Comments#id#") and

    replace(form["Comments#id#"], "'", "", "all") neq ""

    Inspiring
    September 20, 2011

    Agreed.  I see no reason for either the evaluate() or the reReplace() (as opposed to just a replace() call there.

    --

    Adam