Java cyrillic encoding

牧云@^-^@ 提交于 2020-01-06 08:22:35

问题


I have input string - UAH;"Ãîëüô 855229-7", it should be displayed like UAH;"Гольф 855229-7", I'm trying to use Cp1251 encoding, but get output UAH;"????? 855229-7".

String cyrillic = row[0] + row[1];
String utf8String= new String(cyrillic.getBytes("Cp1251"), "UTF-8");
lbl1.setText(utf8String);

回答1:


UTF-8 has nothing to do with this. All of your characters in cyrillic are being represented as single bytes.

Currently, those bytes are in the ISO 8859-1 encoding, also known as Latin-1, which is a subset of the Windows English code page, Cp1252. So, you want to encode the string as Cp1252, then decode the resulting bytes as Cp1251:

String corrected8String = new String(cyrillic.getBytes("Cp1252"), "Cp1251");


来源:https://stackoverflow.com/questions/48097025/java-cyrillic-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!