简体   繁体   English

如何使用C#语言显示5位(十六进制)字符Unicode

[英]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). 我想在屏幕上打印一个具有5个十六进制数字的Unicode字符(例如,将其写在Windows窗体按钮上)。

For example, the Unicode of the character Ace Heart is 1F0B1. 例如,字符Ace Heart的Unicode为1F0B1。 I tried it with \\x but it can present up to 4 digits. 我用\\x尝试过,但是最多可以显示4位数字。

You can use the \\U escape sequence: 您可以使用\\U转义序列:

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. 顺便说一句,我强烈建议避免使用\\x转义序列,因为它们很难阅读。 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". 一起呈现时,乍一看似乎它们都是“ Bell:”,然后是U + 0007,然后是“ Good编译器”或“ Bad”编译器...但是,因为“ Bad”完全由有效的十六进制字符组成,第二个字符串实际上是“ Bell:”,后跟U + 7BAD,后跟“编译器”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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