0

I get strings with Unicode emojis like

$F09F998A

or

$F0 $9F $99 $8A

or

\xF0\x9F\x99\x8A

-> from an SQL database.

s1 := '$F09F998A'; // From Database
s2 := '$F0 $9F $99 $8A'; // From Database
s3 := '\xF0\x9F\x99\x8A'; // From Database

How do I convert s1,s2,s3 to display as in e.g., a TMemo element?

How do I convert s1,s2 or s3?

// Memo1.lines.add('how to convert ' + ????? -> $F0 $9F $99 $8A );

Memo1.lines.add('how to convert ' + s1 + s2 + c3 + ' as Emoji?');

I want convert < s := '\xF0\x9F\x99\x8A'; > to add to a Memo field to show as Emoji.

function convert_as_Emoji(s: string):string;
begin
  result := ???
end;

and then

var s : string;

s := '\xF0\x9F\x99\x8A'; 

Memo1.lines.add(convert_as_Emoji(s));
mjn
  • 36,362
  • 28
  • 176
  • 378
Ingo
  • 5,239
  • 1
  • 30
  • 24

1 Answers1

0

Now I do this with success:

In UTF-8, is bytes $F0 $9F $99 $8A – Remy Lebeau

procedure TForm1.Button1Click(Sender: TObject);
var
  bytes: array[0..3] of byte;
  str: string;
const emoji = '$F0$9F$99$8A';  //  
begin
  bytes[0] := strtoint('$F0'); // bytes[0] := $F0;
  bytes[1] := strtoint('$9F'); // bytes[1] := $9F;
  bytes[2] := strtoint('$99'); // bytes[2] := $99;
  bytes[3] := strtoint('$8A'); // bytes[3] := $8A;

  str := TEncoding.UTF8.GetString(bytes);
  showmessage(str);
end;
Ingo
  • 5,239
  • 1
  • 30
  • 24
  • 1
    But as per your ambiguous descriptions this is not "_converting_" from `'\xF0\x9F\x99\x8A'` because the latter is a String with leading backslashes and the character `x`, and so is `'$F0 $9F $99 $8A'` nowhere converted, too. Where's your routine to extract the values from the String to turn into separate Bytes? You're not even **converting** from `$F09F998A`. Do you even know you can make a String out of `#$F0#$9F#$99#$8A`? – AmigoJack Jan 06 '23 at 12:57
  • @AmigoJack: -> Where's your routine to extract the values from the String. -> you can write the basic routine yourself -> try splitstring; – Ingo Jan 07 '23 at 11:29
  • This version of your "answer" is even worse than the first - every sane person would actually make use of the `emoji` constant and use [`Ord()`](https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Ord) from start to end of a String per character. I wasn't asking about how to split Strings - I was showing up how improperly you formulated question (needing 6 edits), comments and answer. That's why users want blacklists: to never help those again who keep half of everything in their head to later surprise everyone with a "correct" "solution". – AmigoJack Jan 07 '23 at 21:09
  • @AmigoJack: can you anything say to the question : Displaying Unicode emoji \xF0\x9F\x99\x8A from SQL chat database in TMemo -> try the Button1Click code from my answer – Ingo Jan 07 '23 at 21:29