String a="健康";
a = new String(a.getBytes("gbk"),"ISO-8859-1");打印 a = ????111实际我是要得到为½¡¿µ111在debug中可以看到正确的值,但是打印出来或者插入数据库都是????111

解决方案 »

  1.   


    都说gbk转latin1只要
    new String(a.getBytes("gbk"),"ISO-8859-1");
    就可以但是我是就是转不了。
      

  2.   


    能不能说明白点啊,public static void main(String[] arghs) throws UnsupportedEncodingException{
    String a="健康1";

    String s ="";
    for(int i=0;i<a.length();i++){
    byte[] d = a.getBytes();
    System.out.println(d[i]);
    }
    }打印得到
    -67
    -95
    -65
      

  3.   

    String a = "健康";
    String q = new String(a.getBytes("gbk"), "iso-8859-1");
    System.out.println(a);
    String b = "½¡¿µ";
    System.out.println("½¡¿µ");
    System.out.println("\u00BD\u00A1\u00BF\u00B5".equals(b));
    System.out.println("\u00BD\u00A1\u00BF\u00B5".equals(a));
    System.out.println("\u00BD\u00A1\u00BF\u00B5".equals(q));
    System.out.println("\u00BD\u00A1\u00BF\u00B5");
    中间的equals是false
    另外两个是true
    但是打出来一般是4个问号
    实际上转是转对了
    但控制台不给你好好显示
      

  4.   


    我的页面编码是gbk.数据库是latin1(历史问题)
    从数据库里可以正确出来,但是进去的时候是乱码。
    怎么解决,谢谢。。
      

  5.   

    中文转为unicode或其他兼容latin的字符集存储
      

  6.   


    中文 如何 转为unicode啊,不会
      

  7.   


    我就是这样转的,没用
    new String(a.getBytes("gbk"), "iso-8859-1")进入数据库后都是????,也转换不回来了 。在当个class中是可以转回来的
      

  8.   

    数据库存的都是??
    必然转不回来
    那个拉丁文转unicode可以试试这个
        public static String toUnicode(String s) throws Exception {
         if(s == null) {
         return null;
         }
         char[]chars=s.toCharArray();
         StringBuffer sb = new StringBuffer();
         for(int i=0;i<chars.length;i++){//�����
         sb.append("\\"+"u");
         String temp = Integer.toHexString((int)chars[i]).toUpperCase();
         for(int j=0;j<4-temp.length();j++) {
         sb.append("0");
         }
         sb.append(temp);
      }
         return sb.toString();
        }
        public static void main(String[]args) throws Exception {
         String s = "½¡¿µ";
         System.out.println(Native2Ascii.toUnicode(s));
         String b = Native2Ascii.toUnicode(s);
         System.out.println(b);
        }
      

  9.   


    那这个
    \u00BD\u00A1\u00BF\u00B5
    \u00BD\u00A1\u00BF\u00B5
    怎么回到中文呢
      

  10.   

    String ss = "\u00BD\u00A1\u00BF\u00B5";
    String k = new String(ss.getBytes("iso-8859-1"),"gbk");
    System.out.println(k);
      

  11.   


    要这个方法
    toUnicode(String s)
    的反转。方法Unicode转拉丁文
      

  12.   


    有没有 Unicode转拉丁文 的方法