Skip to main content
WolfShade
Legend
September 14, 2012
Question

Confusing variable replaceNoCase issue

  • September 14, 2012
  • 3 replies
  • 1293 views

Hello, everyone.

A co-worker asked for a second set of eyes regarding an issue he was having.  Pulling text from a database, said text was put in a loop with several replaceNoCase() statements, then displayed as an attribute of an anchor tag; so, obviously, one of the replacements is the double quote.  Every version of the double quote that we could think of was part of the loop, so it was looking for the standard quote, MS smart quotes, etc., and even included chr(34), all to be replaced with ".

Except for some strange reason, every other replace was working, but the " was still appearing and breaking the anchor attributes.

After a while of trying to understand what was happening, my co-worker (as a test) set the last line of the loop giving the variable an incremented name (ie, "thisVar" became "thisVar1") and replaced chr(34) with " and then output the new variable name.  Voila.  The replacement worked.

What happened?  Why was every other replace working?  And why did it work when the variable was renamed??

Scratchin' my head on this one.

Thank you,

^_^

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    September 15, 2012

    I, too, am curious. I am sure there is a simple explanation.

    For example, you might have forgotten to set the 4th attribute of the replaceNoCase function to "all". Then if Coldfusion encountered two of more consecutive double-quotes, it would have replaced just the first one.

    Added later: I have assumed you enclosed the text from the database with single-quotes, before doing the replacement.

    WolfShade
    WolfShadeAuthor
    Legend
    September 17, 2012

    No, all of the replaceNoCase() instances have all four attributes, and the last one for all of them is indeed "all".  And the data is enclosed within single quotes.

    ^_^

    Inspiring
    September 14, 2012

    I'd troubleshoot with a short string that contains a double quote.  something like a"b.


    Before and after each replace, I'd output the ascii code of each character in my variable.  That information would probly help me figure it out.

    WolfShade
    WolfShadeAuthor
    Legend
    September 14, 2012

    He's given up on troubleshooting, since it was resolved by changing the variable name on that one specific (and last) replaceNoCase().  I was just posting the question because I would like to understand what went wrong and why. 

    But thank you to you and Adam for responding.

    ^_^

    Inspiring
    September 14, 2012

    It's very difficult to say anything sensible about this without you posting some code which demonstrates what you're talking about.

    --

    Adam

    WolfShade
    WolfShadeAuthor
    Legend
    September 14, 2012

    Unfortunately, this is not feasible.  Our dev systems are isolated from the internet, and I cannot copy/paste the code.  It's about 30 lines of replaceNoCase().

    ^_^

    Inspiring
    September 14, 2012

    What, you can't sneakernet the file from there to a machine you can copy and paste from?

    Anyway, sounds like you've sorted it.

    --

    Adam