将Shift JIS中的拉丁字符转换为Unicode中的拉丁字符 [英] Convert Latin characters from Shift JIS to Latin characters in Unicode

查看:76
本文介绍了将Shift JIS中的拉丁字符转换为Unicode中的拉丁字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用二进制数据中的Shift-JIS编码字符串解析文件.我当前的代码是这样:

I'm working on parsing files with Shift-JIS encoded strings within the binary data. My current code is this:

public static string DecodeShiftJISString(this byte[] data, int index, int length)
{
    byte[] utf8Bytes = Encoding.Convert(Encoding.GetEncoding(932), Encoding.UTF8, data);
    return Encoding.UTF8.GetString(utf8Bytes);
}

它工作正常,并且可以从此方法中获得可用的字符串,尽管当我在WinForms应用程序中显示带有拉丁字符的字符串时,我看到的字符比普通字符宽.

It works fine and I am able to get usable strings from this method, although when I display strings with Latin characters into my WinForms application, I see that the characters are wider than normal.

Shift-JIS字符串中的拉丁字符

我不确定这是我的编码逻辑还是显示字符串的方式问题(我只是将它们直接传递到控件中).任何帮助将不胜感激!

I'm not sure if this is an issue with my encoding logic, or the way I'm supposed to display the strings (I just pass them directly into my controls). Any help would be appreciated!

推荐答案

这些不是普通的ASCII字符,它们是U + FF01范围内的全角变体"

These aren't normal ASCII characters, they're ‘fullwidth variants’ in the range U+FF01 fullwidth exclamation mark upwards. They're for lining up formatting when setting a mixture of Latin and CJK characters.

Unicode更喜欢像这样的奇怪字符,它们只是现有字符的语义相同的样式变体,不存在.但是它必须包括它们才能往返于Shift-JIS之类的传统编码.因此,它们被称为兼容性字符.

Unicode would prefer weird characters like this, which are just semantically-identical stylistic variants of existing characters, not to exist. But it has to include them to round-trip to legacy encodings like Shift-JIS. For this reason they are called Compatibility characters.

您可以使用NFKC等"K"格式的Unicode规范化将兼容字符转换为其基本变体.在Win32中,您可以使用 NormalizeString() a>.

You can convert compatibility characters to their basic variants by using Unicode normalisation with a ‘K’ format such as NFKC. In Win32 you can do this using NormalizeString().

这篇关于将Shift JIS中的拉丁字符转换为Unicode中的拉丁字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆