简体   繁体   中英

How to present a character Unicode with 5 digit (Hex) with c# language

I want to print a Unicode character with 5 hexadecimal digits on the screen (for example to write it on a Windows Forms button).

For example, the Unicode of the character Ace Heart is 1F0B1. I tried it with \\x but it can present up to 4 digits.

You can use the \\U escape sequence:

string text = "Ace of hearts: \U0001f0b1";

Of course, you'll have to be using a font which supports that character...

As an aside, I'd strongly recommend avoiding the \\x escape sequence, as they're hard to read. For example:

string good = "Bell: \x7Good compiler";
string bad = "Bell: \x7Bad compiler";

When presented together, at first glance it would seem that these are both "Bell: " followed by U+0007 followed by either "Good compiler" or "Bad" compiler... but because "Bad" is entirely composed of valid hex characters, the second string is actually "Bell: " followed by U+7BAD followed by " compiler".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM