Convert Unicode to GBK - Android java.lang

Android examples for java.lang:String Unicode

Description

Convert Unicode to GBK

Demo Code


//package com.java2s;

public class Main {
    /**//from   ww w.j  a v  a2  s.  c  o m
     * 
     * @param dataStr
     * @return String
     */

    public static String Unicode2GBK(String dataStr) {
        int index = 0;
        StringBuffer buffer = new StringBuffer();

        int li_len = dataStr.length();
        while (index < li_len) {
            if (index >= li_len - 1
                    || !"\\u".equals(dataStr.substring(index, index + 2))) {
                buffer.append(dataStr.charAt(index));

                index++;
                continue;
            }

            String charStr = "";
            charStr = dataStr.substring(index + 2, index + 6);

            char letter = (char) Integer.parseInt(charStr, 16);

            buffer.append(letter);
            index += 6;
        }

        return buffer.toString();
    }
}

Related Tutorials