首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA Unicode编码与汉语言互换

2012-09-02 
JAVA Unicode编码与中文互换中文转Unicode public static String toUnicode(String s) {String s1 fo

JAVA Unicode编码与中文互换
中文转Unicode

 public static String toUnicode(String s) {        String s1 = "";        for (int i = 0; i < s.length(); i++) {            s1 +="//u" +  Integer.toHexString(s.charAt(i) & 0xffff);        }        return s1;    }


Unicode转中文
 public static String fromUnicode(String unicode){String  str = "";String[] hex = unicode.split("//u");  System.out.println(hex.length);for(int i=1;i<hex.length;i++){         int data = Integer.parseInt(hex[i],16); str+=(char)data; }return str; }

热点排行