Java unicode 转中文
来源:互联网 发布:特种设备考试软件 编辑:程序博客网 时间:2024/05/16 19:10
在java实际开发运用当中,常常会涉及到unicode编码,下面以Demo的方式测试:
/** * @Description: unicode 转换成 中文 * @author Jason.Lau 2015年7月29日 * @param theString * @return */public static String decodeUnicode(String theString) {char aChar;int len = theString.length();StringBuffer outBuffer = new StringBuffer(len);for (int x = 0; x < len;) {aChar = theString.charAt(x++);if (aChar == '\\') {aChar = theString.charAt(x++);if (aChar == 'u') {int value = 0;for (int i = 0; i < 4; i++) {aChar = theString.charAt(x++);switch (aChar) {case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':value = (value << 4) + aChar - '0';break;case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':value = (value << 4) + 10 + aChar - 'a';break;case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':value = (value << 4) + 10 + aChar - 'A';break;default:throw new IllegalArgumentException("Malformed \\uxxxx encoding.");}}outBuffer.append((char) value);} else {if (aChar == 't')aChar = '\t';else if (aChar == 'r')aChar = '\r';else if (aChar == 'n')aChar = '\n';else if (aChar == 'f')aChar = '\f';outBuffer.append(aChar);}} elseoutBuffer.append(aChar);}return outBuffer.toString();}
测试main方法:
/** * @Description: 测试main方法 * @author Jason.Lau 2015年7月30日 * @param args */public static void main(String[] args) {System.err.println(decodeUnicode("\u6d4b\u8bd5\u0055\u006e\u0069\u0063\u006f\u0064\u0065\u89e3\u7801"));}
测试结果:
0 0
- JAVA UNICODE转中文
- Java unicode 转中文
- java中文转unicode码
- java中文转unicode码
- Java将Unicode转中文
- Java中文转Unicode码
- unicode格式转中文java程序
- java unicode与汉字中文互转
- java Unicode和中文互转
- Twocold Java将Unicode转中文汉字
- unicode码 java中文
- Java判断中文及中文字符转unicode
- Java判断中文及中文字符转unicode
- C#中文转Unicode、Unicode转中文
- 中文 转 unicode 问题
- unicode 转 中文 ios
- 中文转Unicode
- unicode在线转中文
- [bfs] HDU2102 A计划
- git分支创建失败 dev创建feature失败
- 干货:强化商业模式的七种机制
- False Sharing问题
- MongoDB MapReduce学习笔记
- Java unicode 转中文
- TCP/IP,Http,Socket,XMPP的区别
- Java基础--基本类型
- 多线程二(Runnable接口)
- 排序
- UIViewController的presentedViewController,presentingViewController和parentViewController三个属性
- OC 中的关键词 大全(1)
- bzoj-1042 硬币购物
- codevs contest #1 3944 幻影阁的难题 树形DP+二分