码迷,mamicode.com
首页 > 编程语言 > 详细

gbk utf-8 string java

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

标签:java   ar   sp   c   ef   r   bs   file   har   

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

标签:java   ar   sp   c   ef   r   bs   file   har   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!