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

来源:互联网 发布:软件架构是什么 编辑:程序博客网 时间:2024/05/17 04:37

处理字符串 将字符串中的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();    }}
原创粉丝点击