JAVA UNICODE转中文
2012-04-06 20:26
204 查看
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') { // Read the xxxx 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); } } else outBuffer.append(aChar); } return outBuffer.toString(); } testtest
相关文章推荐
- java Unicode 转为中文
- Java抓取网页上的unicode 数据 "\u5751\u7239\u7889\u5821" 怎么变成中文
- java 中文和unicode字符串互相转换(文件需要保存为gbk2312或者asci格式)
- JAVA unicode转换成中文
- UnicodeToWord(Java将Unicode码转换成中文)
- java国际化,资源文件内的中文再也不必转换为丑陋的unicode
- JAVA unicode转换成中文
- 使用Java将中文字符转换成Unicode编码
- Java unicode中文编码转换和反转
- java-Unicode与中文的转换
- java中国际化properties的Unicode编码文件用命令转化为中文文件
- Unicode编码和中文互转(JAVA实现)
- 中文与Unicode转换--java
- java Unicode与中文互换
- Java unicode 转中文
- Java的中文处理学习笔记:Hello Unicode(2)
- java 读文件中文处理(读出unicode文件 及 写入unicode文件)
- java中文和unicode相互转换
- java Unicode与中文互换
- [转]Java中文处理学习笔记——Hello Unicode