Translating escape sequence

Jim Lambert jiml at netrin.com
Tue Mar 14 20:13:45 EDT 2017


> Jacque wrote:
> 
> I'm dealing with non-English languages, and JSON data retrieved from a 
> database comes in with unicode escape sequences like this: Eduardo 
> Ba\u00f1uls.
> 
> I need to translate those. I can do it by replacing the "\u" with "0x" 
> and then using numToCodepoint() to get the UTF16 character. But there 
> could be many of these in the same string, so I'm looking for a one-shot 
> command that might just do them all.


JSONImport does it.  
If the escaped string is not in JSON format this function will wrap it in JSON then let JSONImport do its thing.

put deEscape("Eduardo Ba\u00f1uls")

function deEscape pEscapedText
	put "{'1':'**dummy**'}" into temp
	replace "**dummy**" with pEscapedText in temp
	replace "'" with quote in temp
	put JSONImport(temp)into pArray
	return pArray[1]
end deEscape

Roundabout but does the trick.

Jim Lambert



More information about the use-livecode mailing list