Jump to content

Working with Emoji data

Recommended Posts

I am storing and retrieving emoji in UTF16 format on a MySQL database.

When I retrieve, i get the data results

"\ud83d\ude0a" for smile emoji (😊)
"\ud83e\udd37\u200d\u2640" (for🤷‍♀️)

Is there a simple way to convert the UTF16 to unicode and render the emoji on a browser?


Link to post
Share on other sites
  • Administrators

Phew, that took some digging, but I found a solution:

function ConvertFromUCS16(Value: String): String;
  //Make sure any " are escaped
  for var i:=Length(Value) downto 1 do
    if (Value[i]='"') and ((i=1) or (Value[i-1]<>'\')) then

Solution from: https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode

Edit: Whoops, fixed a bug in the escaping

Edit2: Add System.JSON to uses clause.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...