美文网首页
安卓笔记本 - Unicode转汉字

安卓笔记本 - Unicode转汉字

作者: SocialException | 来源:发表于2018-09-02 16:00 被阅读0次

String unicodeStr = [unicode字符串];

StringBuilder retBuf = new StringBuilder();

int maxLoop = unicodeStr.length();

for (int i = 0; i < maxLoop; i++) {

    if (unicodeStr.charAt(i) == '\\') {

        if ((i < maxLoop - 5) && ((unicodeStr.charAt(i + 1) == 'u') || (unicodeStr.charAt(i + 1) == 'U'))) {

            try {

                retBuf.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));

                i += 5;

            } catch (NumberFormatException localNumberFormatException) {

                retBuf.append(unicodeStr.charAt(i));

            } else {

                retBuf.append(unicodeStr.charAt(i));

            }

        } else {

            retBuf.append(unicodeStr.charAt(i));

        }

    }

unicodeStr = String.valueOf(retBuf);

相关文章

网友评论

      本文标题:安卓笔记本 - Unicode转汉字

      本文链接:https://www.haomeiwen.com/subject/bwemwftx.html