package HUST.Swt;
public class Test
{
public static void main(String[] args)
{
String s = "ab简介";
String tt = gbEncoding(s);
System.out.println(decodeUnicode(tt));
}
public static String gbEncoding(final String gbString)
{
char[] utfBytes = gbString.toCharArray();
for (int i = 0; i < utfBytes.length; i++)
System.out.println(utfBytes[i]);
String unicodeBytes = "";
for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++)
{
String hexB = Integer.toHexString(utfBytes[byteIndex]);
if (hexB.length() <= 2)
{
hexB = "00" + hexB;
}
unicodeBytes = unicodeBytes + "\\u" + hexB;
}
System.out.println("unicodeBytes is: " + unicodeBytes);
return unicodeBytes;
}
public static String decodeUnicode(final String dataStr)
{
int start = 0;
int end = 0;
final StringBuffer buffer = new StringBuffer();
while (start > -1)
{
end = dataStr.indexOf("\\u", start + 2);
String charStr = "";
if (end == -1)
{
charStr = dataStr.substring(start + 2, dataStr.length());
}
else
{
charStr = dataStr.substring(start + 2, end);
}
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(new Character(letter).toString());
start = end;
}
return buffer.toString();
}
}
分享到:
相关推荐
汉字与unicode转换工具
汉字与UNICODE转换,十进制和十六进制
汉字与UNICODE之间相互转换,使用起来相当方便。
汉字unicode转换器,方便汉字和UNICODE之间转换!
该工具支持汉字和unicode之间的相互转换器
汉字Unicode转换器,汉字Unicode可以相互转换
本源码是一个中文汉字与Unicode编码转换工具,采用WinForm进行开发,实现中文汉字与Unicode编码互相转换的功能。菜单功能:1、中文汉字转换成Unicode编码2、Unicode编码转换成中文汉字注意事项:1、开发环境为Visual...
汉字与unicode相互转换 上到下汉字转unicode下到上unicode转汉字
unicode 汉字转换器 unicode 汉字转换器 基于java编写,是个jar包,安装jdk后,直接双击
Java中文成Unicode码及从Unicode码转成中文
unicode汉字转换unicode汉字转换unicode汉字转换unicode汉字转换unicode汉字转换
汉字与UNICODE十进制十六进制转换 破解、汉化英文软件时很适用。
可以直接在c语言中使用,数组左列为unicode,根据unicode的数值大小从小到大进行排序,右列为对应的GB2312编码,旁边有注释对应的汉字,亲测可以在单片机上使用,建议用二分法搜索unicode然后转换为GB2312。...
汉字与UnIcode转换,UnIcode与汉字转换,二者互相转换工具。
Unicode和中文的相互转换——VS2019的C++控制台项目(x64\x86\Debug\Release已编译) 1. bool ChineseToUnicode(CString cstr, string & str); 望断秋高和待雪初平__ChineseToUnicode:\u671b\u65ad\u79cb\u9ad8\u...
excel 公式 自动转换unicode编码为汉字
实现Unicode和汉字的互相转码,解压后excel文档直接转换,方便快捷。
小巧好用的编码转换工具,输入中文,一点按钮就出来转换后的unicode