Skip to main content
WolfShade
Legend
Dec 15, 2015 6:01 PM UTC
Question

ReplaceNoCase and REreplaceNoCase not working

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 is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    BKBK
    Community Expert
    Community Expert
    Dec 15, 2015 8:36 PM UTC

    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"

    Translate
    WolfShade
    WolfShadeAuthor
    Legend
    Dec 16, 2015 5:19 AM UTC

    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,

    ^_^

    Translate
    Legend
    Dec 15, 2015 7:21 PM UTC

    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.

    Translate