首页 > 编程语言 > 详细

gbk utf-8 string java

时间:2014-09-12 18:37:43      阅读:352      评论:0      收藏:0      [点我收藏+]

String d = "汗d";
String e = "喊";
String f = "d";
System.out.println("String length is " + d.length() + ". " + d.getBytes("GBK").length
+ " bytes in GBK or " + d.getBytes("UTF-8").length
+ " bytes in UTF-8");

System.out.println("char array length is " + d.toCharArray().length);
System.out.println("String length is " + e.length() + ". " + e.getBytes("GBK").length
+ " bytes in GBK or " + e.getBytes("UTF-8").length
+ " bytes in UTF-8");
System.out.println("char array length is " + e.toCharArray().length);
System.out.println("String length is " +f.length() + ". " + f.getBytes("GBK").length
+ " bytes in GBK or " + f.getBytes("UTF-8").length
+ " bytes in UTF-8");
System.out.println("char array length is " + f.toCharArray().length);

System.out.println("default encoding is " +System.getProperty("file.encoding"));

 

//output

String length is 2. 3 bytes in GBK or 4 bytes in UTF-8
char array length is 2
String length is 1. 2 bytes in GBK or 3 bytes in UTF-8
char array length is 1
String length is 1. 1 bytes in GBK or 1 bytes in UTF-8
char array length is 1
default encoding is UTF-8

//output - 2

 

String length is 2. 3 bytes in GBK or 4 bytes in UTF-8
char array length is 2
String length is 1. 2 bytes in GBK or 3 bytes in UTF-8
char array length is 1
String length is 1. 1 bytes in GBK or 1 bytes in UTF-8
char array length is 1
default encoding is GBK

gbk utf-8 string java

原文:http://www.cnblogs.com/dawnand/p/3968679.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!