用 native2ascii 把你的.java文件变成相应的unicode文件,然后再编译运行

解决方案 »

  1.   

    结果为什么不正确?输出 65313,这是它的 Unicode 码。public class Test {
        public static void main(String[] args) {
            char a = 'A';
            int b = a;
            int c = 'A';
            System.out.println(b);
            System.out.println(c);
        }
    }
      

  2.   

    if(string.getBytes().length==string.length){
    全是半角
    }
    if(string.getBytes().length==string.length*2){
    全是全角
    }
    if(string.getBytes().length!=string.length && string.getBytes().length!=string.length*2){
    全角半角混合
    }
      

  3.   

    JAVA 的char 是unicode的
    int a = 'A';
    而'A'的unicode为 0x21ff 转成intel int 格式为0xff21 即:65313
    如果要得到 'A'的GBK内码,可以这样:
        String t="A";
        byte[] bs=t.getBytes();
    这时:bs[0]=-93,bs[1]=-63 即0xA3, 0xC1
    而'A'的GBK内码就是0xA3C1
      

  4.   

    全角字符 2个字节,4byte,最高位是-1
      

  5.   

    有时间可以看看我的blog 里面有相应的程序,用来对全角和半角进行相互转换
    bolg.csdn.net/onlyfor_love
      

  6.   

    写错了!
    呵呵blog.csdn.net/onlyfor_love
      

  7.   

    我在linux下面这样写:
    String test = "A";//这里A是全角字符byte[] bs = test.getBytes();int x = bs.length;得到的x竟然是1,请问是为什么
      

  8.   

    我不知你的linux是什么版本或JDK是什么版本
    我用linux 9+JDK1.5 结果为2
    不过我记得回过一贴,在linux下jdk1.4对unicode支持有些问题,
    如果你是jdk1.4,升到jdk1.5试试
    (我在solaris下也试过,结果也是2)
      

  9.   

    String test = "ABCD";
    byte[] bs = test.getBytes();
    int y = test.length();
    int x = bs.length;
    System.out.println(y);
    System.out.println(x);这个测试程序 我在window 2000得到的结果是y=2 x= 2
    我上面也说过一个全角字符占2个字节,所以y的值是2就不用怀疑的!
    关键是x的值,因为这个值是由getBytes()得到的,仔细看看jdk的帮助文档,你会发现这个值是不唯一确定的,它和操作系统的默认编码有关系。public byte[] getBytes()
    Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.