// 汉字转化成unicode
public static void encodeUnicode(final String gbString) {
char[] utfBytes = gbString.toCharArray();
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);
}
//unicode转化汉字
public static StringBuffer decodeUnicode(final String dataStr) {
final StringBuffer buffer = new StringBuffer();
String tempStr = "";
String operStr = dataStr;
if (operStr != null && operStr.indexOf("\\u") == -1)
return buffer.append(operStr);
if (operStr != null && !operStr.equals("")
&& !operStr.startsWith("\\u")) {
tempStr = operStr.substring(0, operStr.indexOf("\\u"));
operStr = operStr.substring(operStr.indexOf("\\u"), operStr.length());// operStr字符一定是以unicode编码字符打头的字符串
}
buffer.append(tempStr);
// 循环处理,处理对象一定是以unicode编码字符打头的字符串
while (operStr != null && !operStr.equals("")&& operStr.startsWith("\\u")) {
tempStr = operStr.substring(0, 6);
operStr = operStr.substring(6, operStr.length());
String charStr = "";
charStr = tempStr.substring(2, tempStr.length());
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(new Character(letter).toString());
if (operStr.indexOf("\\u") == -1) {
buffer.append(operStr);
} else { // 处理operStr使其打头字符为unicode字符
tempStr = operStr.substring(0, operStr.indexOf("\\u"));
operStr = operStr.substring(operStr.indexOf("\\u"), operStr.length());
buffer.append(tempStr);
}
}
return buffer;
}
分享到:
相关推荐
C# 格式的ASCII到Unicode转化源码,可以支持包括 Unicode 在内的若干种字符集,有 C# 源码参考。
python-slugify:Python slug 化库,可以把 unicode 转化为 ASCII。
下面小编就为大家带来一篇用PHP将Unicode 转化为UTF-8的实现方法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
汉字跟Unicode 互相 转化 C# 代码
单片机上经常用到,特别是手机编码的转换。有了此表,一切都是那么的容易······
Reflector这个软件还不支持Unicode ,需要自己写一个转化程序,两个搭配起来用极爽!
这是个人自己写的一个shellcode与unicode两种代码之间互相转换的一个工具。
python-slugify:Python slug 化库,可以把 unicode 转化为 ASCII。
解决无法将 Unicode 字符串转换为 Ebcdic 字符串的问题
方便国际化资源文件转换,自己随手写的小工具。
ANSI,Unicode转化,基本的编程规范
汉字转化Unicode
unicode unicode unicode unicode 转化器 抓唤起转换器
中文转化为unicode格式的方法类,经过程序验证完全可使用。
utf-8、ANSI、Unicode相互转化c++实现 std::string ConverANSI2UTF8(const std::string & str); std::wstring ConverANSI2Unicode(const std::string str); std::wstring ConverUTF82Unicode(const std::string str)...
有的时候,遇见中文都被转化成了Unicode内码,看着很不爽,于是写了这么个小工具,用来将Unicode内码转换为中文,可以实现整篇的转换。 另外,此工具也可以将中英文转换为Unicode内码(您可以选择是否将英文转换)...
编写API的目的,Zebra官方提供的Unicode转化组件FNTHEX32.DLL,是一个非托管组件,托管环境下还需要再封装。 该组件直到现在还未找到对应的64位程序兼容组件,为了解决32位和64位的兼容问题,最后编写开发此API, 此...
对url进行编码转换,在实际应用中url的传输的是unicode的编码,因此每次提交url之前需要将其转化 这里是C/C++版的url转化,使用的是char格式的转换,但便于操作在最后将其转化为CString传输,可以根据需要对其进行...
非常简单的 Unicode 和 UCN 转换脚本工具,是一个页面的。