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

ReplaceNoCase and REreplaceNoCase not working

LEGEND ,
Dec 15, 2015 Dec 15, 2015

Copy link to clipboard

Copied

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,

^_^

Views

368

Translate

Translate

Report

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
Advocate ,
Dec 15, 2015 Dec 15, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Dec 15, 2015 Dec 15, 2015

Copy link to clipboard

Copied

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"

Votes

Translate

Translate

Report

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 ,
Dec 15, 2015 Dec 15, 2015

Copy link to clipboard

Copied

LATEST

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,

^_^

Votes

Translate

Translate

Report

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
Documentation