Java implementation of Chinese characters to unicode and Chinese characters to hexadecimal examples
- 2020-04-01 03:31:42
- OfStack
This article illustrates the Java implementation of Chinese characters to unicode and Chinese characters to hexadecimal. Share with you for your reference. The specific implementation method is as follows:
First, Chinese characters to unicode
public static String toUnicode(String s)
{
String as[] = new String[s.length()];
String s1 = "";
for (int i = 0; i < s.length(); i++)
{
as[i] = Integer.toHexString(s.charAt(i) & 0xffff);
s1 = s1 + as[i]+"t";
}
return s1;
}
Second, Chinese characters to hexadecimal system
public static String toChineseHex(String s)
{
String ss = s;
byte[] bt = ss.getBytes();
String s1 = "";
for (int i = 0; i < bt.length; i++)
{
String tempStr = Integer.toHexString(bt[i]);
if (tempStr.length() > 2)
tempStr = tempStr.substring(tempStr.length() - 2);
s1 = s1 + tempStr + " ";
}
return s1.toUpperCase();
}
I hope this article has been helpful to your Java programming.