/**
* js计算字符的长度,匹配双字节字符(包括汉字),
* @author ferndean
*/
myLen : function(str)
{
var len = str.length;
var relen = 0;
for(var i=0; i<len; i++)
{
if(str.charCodeAt(i) <27 || str.charCodeAt(i) >126 )
{
relen += 2;
}else
{
relen ++;
}
}
return relen;
}
java判断一个字串是否包含中文:
/**
* 判断字段是否包含中文
*
* @param str
* @return
*/
public boolean includeChinese(String str)
{
final int max = 0xff00;
boolean isIncluCH = false;
for (int i = 0; i < str.length(); i++)
{
char c = str.charAt(i);
if ((c & max) != 0)
{
isIncluCH = true;
break;
}
}
return isIncluCH;
}