package com.xxx.util;
import java.io.UnsupportedEncodingException;
public class Unicode {
public static void main(String[] args) throws UnsupportedEncodingException {
String s = "鄂327";
System.out.println(gbEncoding(s));
}
public static String gbEncoding(String gbString) {
char[] arr = gbString.toCharArray();
String unicodeBytes = "";
for (int i = 0; i < arr.length; ++i) {
if (!(isChinese(arr[i]))) {
unicodeBytes = unicodeBytes + arr[i];
} else {
if (i != 0) {
unicodeBytes = unicodeBytes + "-";
}
String hexB = Integer.toHexString(arr[i]);
if (hexB.length() <= 2) {
hexB = "00" + hexB;
}
unicodeBytes = unicodeBytes + "un" + hexB;
if (i != arr.length - 1)
unicodeBytes = unicodeBytes + "-";
}
}
return unicodeBytes;
}
public static String
中文转UNICODE
最新推荐文章于 2024-04-03 16:38:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)