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

Confusing variable replaceNoCase issue

LEGEND ,
Sep 14, 2012 Sep 14, 2012

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,

^_^

1.2K
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 ,
Sep 14, 2012 Sep 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

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 ,
Sep 14, 2012 Sep 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().

^_^

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 ,
Sep 14, 2012 Sep 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

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 ,
Sep 14, 2012 Sep 14, 2012

Adam Cameron. wrote:

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

No burning permission for CDs, no flash drives, no nothing. 

^_^

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 ,
Sep 14, 2012 Sep 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.

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 ,
Sep 14, 2012 Sep 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.

^_^

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
Community Expert ,
Sep 15, 2012 Sep 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.

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 ,
Sep 17, 2012 Sep 17, 2012
LATEST

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.

^_^

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