Jump to content
COMFIED

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?

 

Share this post


Link to post
Share on other sites

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

function ConvertFromUCS16(Value: String): String;
begin
  //Make sure any " are escaped
  for var i:=Length(Value) downto 1 do
    if (Value[i]='"') and ((i=1) or (Value[i-1]<>'\')) then
      Insert('\',Value,i);
  result:=TString.DecodeURIComponent(JSON.parse('"'+Value+'"'));
end;

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×