Un-escaping unicode

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
pkoopmanpk
Posts: 47
Joined: Wed Apr 26, 2017 7:12 pm

Un-escaping unicode

Post by pkoopmanpk » Thu Jul 25, 2024 8:19 pm

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?

Post Reply