中文转Unicode
Unicode转中文
public static String toUnicode(String s) {
String s1 = "";
for (int i = 0; i < s.length(); i++) {
s1 +="//u" + Integer.toHexString(s.charAt(i) & 0xffff);
}
return s1;
}Unicode转中文
public static String fromUnicode(String unicode){
String str = "";
String[] hex = unicode.split("//u");
System.out.println(hex.length);
for(int i=1;i<hex.length;i++){
int data = Integer.parseInt(hex[i],16);
str+=(char)data;
}
return str;
}
本文介绍了如何在程序中实现中文字符串与Unicode编码之间的相互转换。通过两个实用的方法:一个是将中文字符转换为Unicode编码,另一个是从Unicode编码还原成中文字符,文章提供了具体的代码示例并解释了其工作原理。
6276

被折叠的 条评论
为什么被折叠?



