utf-8中文标点占几个字节

测试代码:

    public static  void  main(String args[]){
    String aaa="中";
    String aaa2="s";
    String aaa3=",";
    String aaa4="-";
    String aaa5="0";
    try {
        int length = aaa.getBytes("utf-8").length;
        int length2 = aaa2.getBytes("utf-8").length;
        int length3 = aaa3.getBytes("utf-8").length;
        int length4 = aaa4.getBytes("utf-8").length;
        int length5 = aaa5.getBytes("utf-8").length;

        System.out.println("一个中文长度是:"+length);
        System.out.println("英文字母长度是:"+length2);
        System.out.println("中文标点长度是:"+length3);
        System.out.println("英文标点长度是:"+length4);
        System.out.println("数字长度是:"+length5);
    }catch (Exception e){
    }

}

测试结果:

在这里插入图片描述

相关推荐
©️2020 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页