Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复损坏的日语字符编码_C#_Character Encoding - Fatal编程技术网

C# 如何修复损坏的日语字符编码

C# 如何修复损坏的日语字符编码,c#,character-encoding,C#,Character Encoding,我知道下面的字符串应该显示为日语文本 25“AƒeƒBƒBƒgƒRƒXƒZƒBƒgèL”O 有没有办法对文本进行解码和重新编码,使其正确显示?我已经尝试使用shift jis,但它没有生成可读的字符串 string main=“25”XƒZƒBƒgƒL“O.zip”; byte[]mainBytes=System.Text.Encoding.GetEncoding(“shift-jis”).GetBytes(main); string jpn=System.Text.Encoding.GetEn

我知道下面的字符串应该显示为日语文本

25“AƒeƒBƒBƒgƒRƒXƒZƒBƒgèL”O

有没有办法对文本进行解码和重新编码,使其正确显示?我已经尝试使用shift jis,但它没有生成可读的字符串

string main=“25”XƒZƒBƒgƒL“O.zip”;
byte[]mainBytes=System.Text.Encoding.GetEncoding(“shift-jis”).GetBytes(main);
string jpn=System.Text.Encoding.GetEncoding(“shift-jis”).GetString(mainBytes);


谢谢!

我认为原始版本是Shift JIS,但您没有展示您是如何尝试的。因此,下面是我尝试重新编码的:

string s1 = "25“ú‚¨“¾‚ȃAƒ‹ƒeƒBƒƒbƒgƒRƒXƒZƒbƒg‹L”O";
byte[] bs = Encoding.GetEncoding(1252).GetBytes(s1);
string s2 = Encoding.GetEncoding(932).GetString(bs);
s2
现在是
“25日お得なアルティャBトコスセット記念",看起来更像日语

我假设一些字节数组表示文本移位JIS编码,通过使用不同的编码(可能是Windows-1252)读取。因此,首先我尝试返回原始字节数组。然后我使用正确的编码来获得正确的文本

关于我的代码的一些注释:

  • 1252是Windows-1252的数字ID,最常被错误编码使用。但这只是一个猜测,您可以尝试其他编码,看看它是否更有意义
  • 932是Shift JIS的反数字ID(您也可以使用字符串名称)。这也是一个猜测,但可能是正确的
  • 考虑到使用错误的编码通常不是可逆的过程,因此在翻译过程中可能会丢失字符

谢谢rodrigo!这解决了我的问题!我使用shift-jis来获取字节,而不是Windows-1252。在字节上使用shift-jis生成正确的输出。再次感谢!