How do you convert a single Unicode code point to a string?

Let’s say I have the following code point: u1F64A (which is the :speak_no_evil: emoji).

This can be written as:

string monkey = \u1F64A;

How would I convert a known codepoint (as an integer) to a string at runtime though? I’m using RTL.

int codepoint = 0xF64A;
string monkey = //?

There’s some APIs in Elements RTL, in https://github.com/remobjects/RTL2/blob/master/Source/String.Unicode.pas.

In particular, UnicodeCodePoint.ToUTF16 or UnicodeCodePoint.ToUTF16String should do what you need.

Feedback on these appreciated, as I don’t think anyone by me ever used these before :wink:

Seems to work a treat. Thanks!

I’ll let you know if I find an edge case.

1 Like