通过不同的输出编码输出 Unicode 值 C#

发布于 2025-01-15 14:28:29 字数 581 浏览 3 评论 0原文

我正在尝试控制台输出选项并注意到这一点:

Console.OutputEncoding = System.Text.Encoding.Unicode;
    Console.WriteLine("\u266F");
    Console.WriteLine("\u6F26");

所以我将编码设置为 Unicode(UTF-16LE) 并且我尝试输出尖锐字符 "\u266F" 这是 UTF-8 中的升号 "\u6F26" 这是 UTF-16LE 中的锐号

您可以在屏幕截图中看到输出在此处输入图像描述

所以我有 2 个问题

  1. 为什么这个“\u266F”输出锐利时它是 UTF-8 格式,我已将编码器设置为 Unicode

  2. 如果它在 UTF-16LE 格式且编码器为 UTF- 格式,为什么不输出锐号? 16LE也是。

I am experimenting with the Console Output Options and have noticed this:

Console.OutputEncoding = System.Text.Encoding.Unicode;
    Console.WriteLine("\u266F");
    Console.WriteLine("\u6F26");

So I set the Encoding to Unicode(UTF-16LE) and I am trying to output the sharp character
"\u266F" This is the sharp in UTF-8
"\u6F26" This is the sharp in UTF-16LE

You can see the output in the screenshotenter image description here

So I have 2 questions

  1. Why does this "\u266F" output a sharp when It is in UTF-8 and I have set the Encoder to Unicode

  2. Why doesn't this output a sharp if it is in UTF-16LE and the Encoder is in UTF-16LE too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文