gpt4 book ai didi

java - 字符串编码 - Shift_JIS/UTF-8

转载 作者:行者123 更新时间:2023-11-29 05:06:01 26 4
gpt4 key购买 nike

我从第 3 方库中获取了一个字符串,该字符串编码不正确。不幸的是,我不允许更改库或使用另一个库...

因此,实际问题是,第 3 方库结果字符串会将“è ò à ù ì ä ö ü, ...”等字符编码为 UTF-8 字符串中的 SHIFT_JIS(汉字)。但前提是该字符连接到一个词并且不是独立的。

例如:

"Ö Just a simple test"

Standalone

"ÖJust a simple test"

Connected

我尝试了以下但没有成功:

byte[] b = resultString.getBytes("Shift_JIS");
String value = new String(b, "UTF-8");

更新 1:

这就是“resultString”的内容。

注意:显示的字节数组没有任何修改(例如 getBytes("Shift_JIS"),它只是作为字节的 resultString)

enter image description here enter image description here

你有什么想法吗?任何帮助将不胜感激。谢谢。

最佳答案

嗯,很奇怪:

作为

byte[] b = resultString.getBytes("Shift_JIS");
String value = new String(b, "UTF-8");

对我不起作用,我尝试了以下方法:

String value = new String(resultString.getBytes("SHIFT-JIS"), "UTF-8")

像魅力一样工作。可能是因为“Shift_JIS”中的下划线和小写字符。

关于java - 字符串编码 - Shift_JIS/UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com