在Java中,字符使用的是Unicode码,不论是否汉字、ABC长度都为一。你可以用byte去长度。
String s = "测试";
byte[] b;
try
{
b = s.getBytes("gb2312");
System.out.println(b.length);
}catch(Exception e){}
String s = "测试";
byte[] b;
try
{
b = s.getBytes("gb2312");
System.out.println(b.length);
}catch(Exception e){}
int len=s.getBytes().length;//不必转换
System.out.println(len);//此时len=4;
For U Think It is Chinese
But It Maybe Not Chinese
So at the first u must test if it is Chinese