How to convert unicode codepoint to string in Framework 4.x?

347 views Asked by At

How can I convert 'Supplementary' Unicode code points (21-bit) to System Strings in .NET Framework 4.7.2? It seems that in .NET 5.0, the Char.ConvertFromUtf32() method handles this, but in .NET framework, this method can't handle values above the 'Basic Multilingual Plane' range. I need something like this:

Console.WriteLine(Char.ConvertFromUtf32(0x0001F381));

to produce this: .

I have tried:

int Gift = 0x0001F381;
string strGift = Char.ConvertFromUtf32(Gift);
Console.WriteLine($"Gift (0x{Gift:X}) is {strGift}.");

but it just gives me: Gift (0x1F381) is ??.

How can I code this to work in .NET framework 4.7.2?

1

There are 1 answers

0
JNygrenLT On

The right answer to the question is to use "Char.ConvertFromUtf32".

By trying to show the result in the console, I created an entirely different problem.