Java UTF8 Convert To utf8ToUnicode(String inStr)

Here you can find the source of utf8ToUnicode(String inStr)

Description

utf To Unicode

License

Apache License

Declaration

public static String utf8ToUnicode(String inStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String utf8ToUnicode(String inStr) {

        char[] myBuffer = inStr.toCharArray();

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < inStr.length(); i++) {
            Character.UnicodeBlock ub = Character.UnicodeBlock.of(myBuffer[i]);
            if (ub == Character.UnicodeBlock.BASIC_LATIN) {
                sb.append(myBuffer[i]);//from w  ww. j av a2  s.c  om
            } else if (ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
                int j = (int) myBuffer[i] - 65248;
                sb.append((char) j);
            } else {
                int chr1 = (char) myBuffer[i];
                String hexS = Integer.toHexString(chr1);
                String unicode = "\\u" + hexS;
                sb.append(unicode.toLowerCase());
            }
        }
        return sb.toString();

    }
}

Related

  1. getBytesUtf8(String string)
  2. UTF8ToCodePoint(byte[] b, int s)
  3. utf8ToCodePoint(int b1, int b2, int b3, int b4)
  4. utf8Togb2312(String str)
  5. utf8ToString(byte[] src, int stPos, int utf8Len)
  6. utfToChars(byte[] src, int srcIndex, char[] dst, int dstIndex, int len)