We don't have the cp1251 code page available on a phone, so new String( data, "cp1251" ) doesn't work.
We need a function with signature something like
String ArrayCp1251toUTF8String(byte data[]);
We don't have the cp1251 code page available on a phone, so new String( data, "cp1251" ) doesn't work.
We need a function with signature something like
String ArrayCp1251toUTF8String(byte data[]);
First, there's no such thing as a "UTF-8 string" in Java, they're just strings. But you don't need to worry about the string's encoding, just the encoding of the bytes you're converting. Since
cp1251
(orwindows-1251
) is a single-byte encoding, decoding is a simple matter of using the byte value as an index into an appropriate array ofchar
values. Here's an example: