woshare
这取决于字符编码方式:
一般情况下,
采用ISO8859-1编码方式时,一个中文字符与一个英文字符一样只占1个字节;
采用GB2312或GBK编码方式时,一个中文字符占2个字节;
而采用UTF-8编码方式时,一个中文字符会占3个字节

public void printStrLength(){
String str="你好";
try {
Integer len_ISO8859_1 = str.getBytes("ISO8859-1").length;// 得到2
Integer len_GB2312 = str.getBytes("GB2312").length;//得到4
Integer len_GBK = str.getBytes("GBK").length;//得到4
Integer len_UTF_8 = str.getBytes("UTF-8").length;//得到6
System.out.println("#####################length=" + str.length());
log.error("#####################length=" + str.length());
}catch (UnsupportedEncodingException e){

}
}

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-09-18
  • 2022-02-16
  • 2021-11-29
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-03
  • 2021-11-29
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案