处理字符串 将字符串中的unicode字符转为汉字

版权声明:本文为博主原创文章,转载时注明出处即可。交流共享,一起进步。 GitHub地址: https://github.com/iamyong https://blog.csdn.net/CapMiachael/article/details/78479943

处理字符串 将字符串中的unicode字符转为汉字



public class UnicodeUtil {

    /**
     * 处理字符串   将字符串中的unicode字符转为汉字
     * @param asciicode
     * @return
     */

    public static String ascii2native ( String asciicode )
    {
        String[] asciis = asciicode.split ("\\\\u");
        StringBuffer nativeValue = new StringBuffer();
         nativeValue.append(asciis[0]) ;
        try
        {
            for ( int i = 1; i < asciis.length; i++ )
            {
                String code = asciis[i];
                nativeValue.append((char) Integer.parseInt (code.substring (0, 4), 16));
                if (code.length () > 4)
                {
                    nativeValue.append(code.substring (4, code.length ())) ;
                }
            }
        }
        catch (NumberFormatException e)
        {
            return asciicode;
        }
        return nativeValue.toString();
    }

}

猜你喜欢

转载自blog.csdn.net/CapMiachael/article/details/78479943
今日推荐