public class Snippet {
/**
* unicode 转换成 中文
*/
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();
}
}
public static void test(String[] args) {
int len = args[0].length();
String[] s = new String[len];
// cn -> unicode
for (int i = 0; i < len; i++) {
char c = args[0].charAt(i);
s[i] = Integer.toString(c, 16);
System.out.println(c + "\t\\u " + s[i]);
}
System.out.println();
// unicode -> cn
for (int i = 0; i < s.length; i++) {
char c = (char) Integer.valueOf(s[i], 16).intValue();
System.out.println("\\u " + s[i] + "\t " + c);
}
}
分享到:
相关推荐
excel 公式 自动转换unicode编码为汉字
这个时候搜索内存时 就需要把汉字转换成unicode的形式 这个小工具就能帮上大忙了。。 注意这个版本有点小问题 就是初始化的时候显示我信息的Unicode 没有。这是我调试时候方便 在初始化窗口的时候注释掉了。。其它...
Java中文成Unicode码及从Unicode码转成中文
只要安装了jdk,都可以转换的简单windows命令,中文转Unicode码和Unicode码转中文,简单、方便、实用。
中文汉字转unicode工具,非常好用,推荐给大家
delphi2009 Unicode转汉字,汉字转Unicode源码 高手就不用看了.
中文转化为unicode格式的方法类,经过程序验证完全可使用。
汉字转 Unicode 码 软件 十六进制 GPRS GSM 手机短信 TC35I C语言 中国电子信息网
在网上找资料很少有汉字直接转GBK编码格式,一般都是汉字转Unicode编码,这套是将汉字先转换成Unicode编码,在通过参照表得出汉字的GBK编码数据。虽然是一个js文件,但是加以修改可以用于很多平台上如:小程序,...
汉字转成unicode的步骤如下,获得汉字的二进制码,然后再unicode查找表中作为索引来查找即可。 该程序使用gb2312标准,囊括了7745个中文常用汉字,程序中未采用系统相关函数,可以在window和linux中使用。
unicode转汉字,汉字转unicode脚本
C#_Unicode字符串 转中文编码 和 字符串转Unicode
这是一款非常实用的,将汉字转换为unicode编码的工具,很实用,输入汉字,点击转换,即可完成转换
Unicode和中文的相互转换——VS2019的C++控制台项目(x64\x86\Debug\Release已编译) 1. bool ChineseToUnicode(CString cstr, string & str); 望断秋高和待雪初平__ChineseToUnicode:\u671b\u65ad\u79cb\u9ad8\u...
将中文转换成unicode格式的操作方法,可根据文档操作流程介绍,配合截图转换中文为unicode格式
将汉字转换成unicodec程序源码,获得汉字的二进制码,然后再unicode查找表中作为索引来查找即可
用vc写的汉字转unicode码,可以得到多进制的unicode码
汉字与unicode相互转换 上到下汉字转unicode下到上unicode转汉字