欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java 截取字符串(判斷漢字)

 更新時(shí)間:2008年11月21日 19:56:52   作者:  
jsp截取中文字符串 len為字節(jié)長(zhǎng)度

復(fù)制代碼 代碼如下:

/**
* 截取字符串 len為字節(jié)長(zhǎng)度
* @param str
* @param len
* @return
* @throws UnsupportedEncodingException
*/
public static String getLimitLengthString( String str,int len){
try{
int counterOfDoubleByte = 0;
byte[] b = str.getBytes("gb2312");
if(b.length <= len)
return str;
for(int i = 0; i < len; i++){
if(b[i] < 0)
counterOfDoubleByte++;
}
if(counterOfDoubleByte % 2 == 0)
return new String(b, 0, len, "gb2312");
else
return new String(b, 0, len - 1, "gb2312");
}catch(Exception ex){
DBTools.error(ex);
return "";
}
}

相關(guān)文章

最新評(píng)論