java Unicode转码
生活随笔
收集整理的這篇文章主要介紹了
java Unicode转码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 //中文轉UNICODE
2 public static String chinaToUnicode(String str) {
3 String result = "";
4 for (int i = 0; i < str.length(); i++) {
5 int chr1 = (char) str.charAt(i);
6 if (chr1 >= 19968 && chr1 <= 171941) {// 漢字范圍 \u4e00-\u9fa5 (中文)
7 result += "\\u" + Integer.toHexString(chr1);
8 } else {
9 result += str.charAt(i);
10 }
11 }
12 return result;
13 }
?
1 //UNICODE轉中文 2 public static String unicodeToChina(String str) throws Exception{ 3 byte[] byteArr = str.getBytes("UTF-8"); 4 String chinese=new String(byteArr,"UTF-8"); 5 return chinese; 6 } 7轉載于:https://www.cnblogs.com/live365wang/archive/2012/07/23/2604404.html
總結
以上是生活随笔為你收集整理的java Unicode转码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: KMP算法详解 网络上转的。。。仰慕此人
- 下一篇: 统计信息及相关说明