Java:如何从字符串“u00C3”等创建Unicode

Java:如何从字符串“u00C3”等创建Unicode,第1张

Java:如何从字符串“ u00C3”等创建Unicode

我在网上的某个地方捡到了这个:

String unescape(String s) {    int i=0, len=s.length();    char c;    StringBuffer sb = new StringBuffer(len);    while (i < len) {        c = s.charAt(i++);        if (c == '\') { if (i < len) {     c = s.charAt(i++);     if (c == 'u') {         // TODO: check that 4 more chars exist and are all hex digits         c = (char) Integer.parseInt(s.substring(i, i+4), 16);         i += 4;     } // add other cases here as desired... }        } // fall through:  escapes itself, quotes any character but u        sb.append(c);    }    return sb.toString();}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5565180.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-14
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存