将中文字符转换为 Unicode
假设我有一个随机的汉字“玩”。我想将其转换为 Unicode,即 U+73A9。我怎样才能在 C# 中做到这一点?
Let's say I have a random Chinese character, 玩. I want to convert it to Unicode, which would be U+73A9. How could I do this in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 myChar 作为引用特殊字符的字符...
上面我们输出字符本身,后跟 Unicode 代码点,然后是整数值。
减少格式字符串和参数以仅输出“U+...”代码...
Take myChar as a char referencing your special character...
Above we're outputting the character itself followed by the Unicode code point and then the integer value.
Reduce the format string and parameters to output only the "U+..." code...
字符玩是 Unicode 格式的。
如果在 C# 中将其称为“玩”,那么它当前采用 UTF-16 格式,这是 Unicode 编码形式之一。
如果您从其他地方获取它,您需要:
第 3 步可能很简单(哦,我只是用那个!)或很困难(该死,必须自己写!)或介于两者之间(嘿,有人已经写过其中之一了吗?!)
The characater 玩 is in Unicode.
If you have it in C# as 玩, then it's currently in UTF-16, which is one of the Unicode encoding forms.
If you are obtaining it from somewhere else you need to:
Step 3 May be simple (oh, I just use that one!) or hard (darn, have to write it myself!) or somewhere in between (hey, anyone written one of these already?!)
一个更长一点的例子,遵循乔恩·汉纳(Jon Hanna)的回答中的模式:
--jeroen
A bit longer example, that follows the pattern in Jon Hanna's answer:
--jeroen