Unicode和中文互轉

public static void main(String[] args) throws UnsupportedEncodingException {
// Unicode轉中文
String unicode1 = “”;
String result = new String(unicode1.getBytes(“UTF-8”), “UTF-8”);
System.out.println(result);
中文轉Unicode
String chinese = “”;
StringBuffer unicode = new StringBuffer();
for (int i = 0; i < chinese.length(); i++) {
Character character = chinese.charAt(i);
unicode.append(“\u” + Integer.toHexString(character));
}
System.out.println(unicode.toString());
}
本人已親測

發佈了38 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章