Highlighted

ReplaceNoCase and REreplaceNoCase not working

LEGEND ,
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

283

Likes

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

ReplaceNoCase and REreplaceNoCase not working

LEGEND ,
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 &quot;

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

284

Likes

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

Likes

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
Reply
Loading...
Dec 15, 2015 0
Adobe Community Professional ,
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"

Likes

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
Reply
Loading...
Dec 15, 2015 0
LEGEND ,
Dec 15, 2015

Copy link to clipboard

Copied

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,

^_^

Likes

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
Reply
Loading...
Dec 15, 2015 0