Skip to main content
WolfShade
Legend
December 15, 2015
Question

ReplaceNoCase and REreplaceNoCase not working

  • December 15, 2015
  • 2 replies
  • 470 views

Hello, all,

I've got a query flattened into a JSON string.  The query does contain double-quotes in some of the data, so I try to strip that out.  I'm replacing " with "

HOWEVER, the action page is using regex replacement to convert back to ", but it isn't completely working.

I've tried the following with ReplaceNoCase() and REReplaceNoCase() - neither is working.

<cfset form.XLJson = ReplaceNoCase(form.XLJson,'&quot;','"','ALL') />

The above code will take:

Smith, John "Johnny"

turn it into

Smith, John &quot;Johnny&quot;

BUT, what it changes back to is

Smith, John ";Johnny";

Am I missing something, here?

V/r,

^_^

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 15, 2015

    WolfShade wrote:

    <cfset form.XLJson = ReplaceNoCase(form.XLJson,'&quot;','"','ALL') />

    The above code will take:

    Smith, John "Johnny"

    turn it into

    Smith, John &quot;Johnny&quot;

    It's the other way round. The function

    replaceNoCase("somethin1 somethin2 substr1 somethin3 substr1", "substr1", "substr2", "all")

    results in

    "somethin1 somethin2 substr2 somethin3 substr2"

    WolfShade
    WolfShadeAuthor
    Legend
    December 16, 2015

    If you use only the code that I provided, yes.  But, if you take the whole post into consideration, then the code that I did not show does as I described.

    As Steve Sommers‌ pointed out, I'm not including the code that encodes " into &quot;.  For a reason.. it's a JavaScript loop that is pulling the values from a table/tr/td and creating the JSON string - I need to make sure that I'm copying CF's format precisely, so that it can create a query object on the action page.  Otherwise, I would have just used jQuery to serialize it.

    The string in JavaScript has two .replace() working on it.  I'm not at work, now, but I'll try to write something similar from memory.

    I have something like:

    str += "[";

    (loop start)

    str += '"' + cellValue.innerHTML.replace(/'/g,'&apos;').replace(/"/g,'&quot;') + '",';

    (loop end)

    str = str.replace(/,$/,'') + "]";

    HTH,

    ^_^

    Legend
    December 15, 2015

    You're only showing half the process - the decoding side. The above looks correct so I'm guessing there is a typo in the encoding side.