Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Unicode character (U+1FXYZ) not outputting correctly when used in code-behind





In my code-behind, I'm trying to return the hexcode for a unicode character.

I'm trying to output any one of these characters for the Segoe UI Symbol font: http://www.istartedsomething.com/uploads/emojisegoe.html. For example, "U+1F60A".

If I do so via my xaml, such as:

FontFamily="Segoe UI Symbol" Text="😊"

Then it works fine.

But if I bind the value to retrieve it via a .cs converter class, the correct character doesn't appear:

FontFamily="Segoe UI Symbol" Text="{Binding Pivot7Days.EmojiWeekendSummary, Converter={StaticResource EmoticonConverter}}"

Converter class:

switch (input)
    case "happy":
        return "\u1F60A";
    case "sad":
        return "\u1F60B";
        return "\u1F610";

I get an entirely different character followed by the final character in the returned string, such as 'A', 'B' or '0'. For example, when I should be seeing a face with tongue out (U+1F60B), I instead get the following:

enter image description here

Am I using the incorrect escape sequence in my code behind?

like image 391
Barrrdi Avatar asked Mar 21 '23 02:03


1 Answers

Characters beyond U+FFFF cannot be directly written as \u.... literals (if you try that, only the first four hex digits are used, and you get a wrong character) but as a surrogate pair or, easier, using an eight-digit \U literal, e.g. '\U0001F60A' for U+1F60A.

like image 118
Jukka K. Korpela Avatar answered Apr 24 '23 00:04

Jukka K. Korpela