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,'"','"','ALL') />
The above code will take:
Smith, John "Johnny"
turn it into
Smith, John "Johnny"
BUT, what it changes back to is
Smith, John ";Johnny";
Am I missing something, here?
V/r,
^_^
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.
Copy link to clipboard
Copied
WolfShade wrote:
<cfset form.XLJson = ReplaceNoCase(form.XLJson,'"','"','ALL') />
The above code will take:
Smith, John "Johnny"
turn it into
Smith, John "Johnny"
It's the other way round. The function
replaceNoCase("somethin1 somethin2 substr1 somethin3 substr1", "substr1", "substr2", "all")
results in
"somethin1 somethin2 substr2 somethin3 substr2"
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 ". 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,''').replace(/"/g,'"') + '",';
(loop end)
str = str.replace(/,$/,'') + "]";
HTH,
^_^