Convert GBK to Unicode - Android java.lang

Android examples for java.lang:String Unicode

Description

Convert GBK to Unicode

Demo Code


//package com.java2s;

public class Main {
    /**//  w  ww. j  a  va2s. c o  m
     * 
     * @param str
     * @return String
     */

    public static String GBK2Unicode(String str) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char chr1 = (char) str.charAt(i);

            if (!isNeedConvert(chr1)) {
                result.append(chr1);
                continue;
            }

            result.append("\\u" + Integer.toHexString((int) chr1));
        }

        return result.toString();
    }

    public static boolean isNeedConvert(char para) {
        return ((para & (0x00FF)) != para);
    }
}

Related Tutorials