public class Conversion
{
//中文转unicode
public Conversion()
{
String s="登录社区";
for(int i=0;i<s.length();i++)
{
int chr1=(char)s.charAt(i);
String result4= "//u" + Integer.toHexString(chr1);
System.out.println(result4);
}
}
public String UnicodeToChinese(String string)
{
String chineseStr= string.replace("//u","|");
String [] s2 = chineseStr.split("|");
String s1 ="";
for (int i=1;i<s2.length;i++)
{
s1=s1+(char)Integer.parseInt(s2[i],16);
}
return s1;
}
public static void main(String args[])
{
//unicode转中文
String str = "/u767b/u5f55/u793e/u533a";
Conversion b=new Conversion();
for(char c : str.toCharArray())
System.out.println(c);
/*或者
String chistr = b.UnicodeToChinese(str);
System.out.println(chistr);
*/
}
}
{
//中文转unicode
public Conversion()
{
String s="登录社区";
for(int i=0;i<s.length();i++)
{
int chr1=(char)s.charAt(i);
String result4= "//u" + Integer.toHexString(chr1);
System.out.println(result4);
}
}
public String UnicodeToChinese(String string)
{
String chineseStr= string.replace("//u","|");
String [] s2 = chineseStr.split("|");
String s1 ="";
for (int i=1;i<s2.length;i++)
{
s1=s1+(char)Integer.parseInt(s2[i],16);
}
return s1;
}
public static void main(String args[])
{
//unicode转中文
String str = "/u767b/u5f55/u793e/u533a";
Conversion b=new Conversion();
for(char c : str.toCharArray())
System.out.println(c);
/*或者
String chistr = b.UnicodeToChinese(str);
System.out.println(chistr);
*/
}
}