How to turn such a string into an emoji? 1F600 => 😀 or 1F600 => \U0001F600 or 1F600 => 0x1F600
I spent a few days but I still didn't understand how to translate a string like 1F600 into emoji
You simply need to convert the value to the code point then get the character at that code point:
var emoji = Char.ConvertFromUtf32(Convert.ToInt32("1F600", 16));
Char.ConvertFromUtf32
.
Commented
Nov 22, 2022 at 7:00
The string "1F600" is the hexadecimal representation of a Unicode code point. As it is not in the BMP, you either need UTF32 or a UTF16 surrogate pair to represent it.
Here is some code to perform the requested conversion using UTF32 representation:
Parse as 32-bit integer:
var utf32Char = uint.Parse("1F600", NumberStyles.AllowHexSpecifier);
Convert this to a 4-element byte array in litte-endian byte order:
var utf32Bytes = BitConverter.GetBytes(utf32Char);
if (!BitConverter.IsLittleEndian)
Array.Reverse(utf32Bytes);
Finally, use Encoding.UTF32 to make a string from it.
var str = Encoding.UTF32.GetString(utf32Bytes);
Console.WriteLine(str);