SHIFT_JIS 和 Unicode 编码之间的转换是否存在问题?

发布于 2024-07-23 01:21:53 字数 298 浏览 1 评论 0原文

我听说 Unicode 和 SHIFT_JIS 代码之间存在(曾经是?)不明确的映射。 这篇知识库文章在一定程度上证明了这一点。

所以问题是:如果我采用 SHIFT_JIS 编码的文本,将其转换为 Unicode 并返回,我会丢失任何数据吗?

详细信息:我正在谈论 Windows(XP 及以上版本)和 .NET(其中理论上依赖于 NLS API)。

I've heard there are (used to be?) ambiguous mappings between Unicode and SHIFT_JIS codes. This KB article somewhat proves this.

So the question is: will I lose any data if I take SHIFT_JIS-encoded text, convert it to Unicode and back?

Details: I'm talking about Windows (XP and on) and .NET (which in theory relies on NLS API).

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零時差 2024-07-30 01:21:53

是的,看起来这仍然会丢失数据:

using System;
using System.Text;

class Test
{
    static void Main(string[] args)
    {
        Encoding shiftJis = Encoding.GetEncoding(932);        
        byte[] original = new byte[] { 0x87, 0x90 };        
        string text = shiftJis.GetString(original);
        byte[] backAgain = shiftJis.GetBytes(text);     
        Console.WriteLine("{0:x}{1:x}", backAgain[0], backAgain[1]);
    }
}

这会打印 81E0,正如您链接到的页面所预测的那样。

Yes, it looks like this will still lose data:

using System;
using System.Text;

class Test
{
    static void Main(string[] args)
    {
        Encoding shiftJis = Encoding.GetEncoding(932);        
        byte[] original = new byte[] { 0x87, 0x90 };        
        string text = shiftJis.GetString(original);
        byte[] backAgain = shiftJis.GetBytes(text);     
        Console.WriteLine("{0:x}{1:x}", backAgain[0], backAgain[1]);
    }
}

This prints 81E0, as predicted by the page you linked to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文