Page 1 of 1

Un-escaping unicode

Posted: Thu Jul 25, 2024 8:19 pm
by pkoopmanpk
Today I recieved a JSon message with an UTF8 string containing ''.

As a quick fix I used the following stop-gap:

Code: Select all

Define_Com Class(#PRIM_REGX) Name(#uRegEx)
Define_Com Class(#PRIM_ALPH) Name(#uPattern)
Define_Com Class(#PRIM_DC.UnicodeString) Name(#uMatch)
Define_Com Class(#PRIM_DC.UnicodeString) Name(#uReplace)
Define_Com Class(#BIG_INT8) Name(#uCode)

#uPattern := '&#[0-9]+;'
Dowhile (#uRegEx.IsMatch( #uPattern #iUnicodeString ))
   #uMatch := #uRegEx.Match( #uPattern #iUnicodeString ).Value
   #uCode := #uMatch.Substring( 3 (#uMatch.CurChars - 3) ).AsNumber
   #uReplace := #uCode.AsUnicodeString
   #iUnicodeString := #iUnicodeString.ReplaceAll( #uMatch #uReplace )
Endwhile
But this will break if it's ' or one of the many other options like '.

Is there an easy way to un-escape these characters?