0

Is there a way to convert a byte array to string with the windows-1251 encoding in Blackberry? i tried

str = new String(mybyteArr, "Windows-1251");

or

str = new String(mybyteArr, "Cp1251");

but I get UnsupportedEncodingException.

I am using Blackberry JRE 5.0.

Vame
  • 2,033
  • 2
  • 18
  • 29

1 Answers1

2

This is not supported right out of the box in the BB API.

BlackBerry supports the following character encodings:

  • "ISO-8859-1"
  • "UTF-8"
  • "UTF-16BE"
  • "US-ASCII"

However if you have an array of bytes and you know this is a string encoded in cp1251, then you may manually create a String from it using smth like this:

StringBuffer sb = new StringBuffer();
char c;
for (int i = 0; i < mybyteArr.length; i++) {
    c = getUnicodeCharForCP1251(mybyteArr[i]);
    sb.append(c);
}

private char getUnicodeCharForCP1251(byte b) {
    // return a matching unicode char for the argument
    // using the table from http://en.wikipedia.org/wiki/Windows-1251
}
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91