4 Replies Latest reply: May 25, 2009 9:08 AM by 791266 RSS

    Problem with Chinese char from utf-16

    807588
      Hi,

      i am trying to convert the UTF-16 string to Chinese characters.The code to do so is as
      follows:
      String str="6BCF8F38";
      char[] buffer = str.toCharArray();
      String unicode = "";
              int code = 0;
              int j = 0;
              char[] unibuffer = new char[buffer.length / 2];
         
                  for (int i = 0; i < buffer.length; i += 2) {
                      code += Character.digit(buffer, 16) * 16;
      code += Character.digit(buffer[i + 1], 16);
      unibuffer[j++] = (char) code;
      code = 0;
      }
      unicode = new String(unibuffer);

      What is happening here is that most of the chars are displayed well (Displayed using SWING) but some chars are square box. For ex : &#27599; 6BCF &#36664; 8F38
      The first one is correctly displayed but the second one is box.
      Any suggestions what is wrong ... Thanks in advance.