Need help determining encoding of the text

2019-08-29 11:29发布

This is cyrillic text of unknown encoding displayed in windows-1251. Pretty sure it's not UTF8, ISO8859-5 or KOI8. I couldn't determine the actual encoding, does anyone has a clue?

Полный кадр

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-29 11:44

So the original string has first been encoded as utf8, then interpreted in iso-8859-1 and then the result again encoded as utf-8. Solution given in java. Assumes you have the raw byte access, otherwise more code is required to get them.

//The underlying bytes are these, based on the characters being displayed in windows-1251

byte[] rawBytes = {(byte)0xc3,(byte)0x90,(byte)0xc2,(byte)0x9f,(byte)0xc3,(byte)0x90,(byte)0xc2,
                    (byte)0xbe,(byte)0xc3,(byte)0x90,(byte)0xc2,(byte)0xbb,(byte)0xc3,(byte)0x90,
                    (byte)0xc2,(byte)0xbd,(byte)0xc3,(byte)0x91,(byte)0xc2,(byte)0x8b,(byte)0xc3,
                    (byte)0x90,(byte)0xc2,(byte)0xb9,(byte)0x20,(byte)0xc3,(byte)0x90,(byte)0xc2,
                    (byte)0xba,(byte)0xc3,(byte)0x90,(byte)0xc2,(byte)0xb0,(byte)0xc3,(byte)0x90,
                    (byte)0xc2,(byte)0xb4,(byte)0xc3,(byte)0x91,(byte)0xc2,(byte)0x80};

//alternatively this will work just as well:
//Charset windows1251 = Charset.forName("Windows-1251");
//byte[] rawBytes = windows1251.encode("Полный кадр").array();

Charset utf8 = Charset.forName("utf-8");
String asUTF8 = utf8.decode(ByteBuffer.wrap(rawBytes)).toString();

//Intermediate step required to convert the intermediate string
//to byte[] again. Iso-8859-1 is used because it maps 256 first 
//unicode points exactly to byte values of 0-255

Charset iso88591 = Charset.forName( "ISO-8859-1");
byte[] bytes = iso88591.encode(asUTF8).array();

String finalResult = utf8.decode( ByteBuffer.wrap(bytes)).toString();
System.out.println(finalResult);
//Полный кадр
查看更多
登录 后发表回答