/**
* 功能:验证字符串长度是否符合要求,一个汉字等于两个字符
* @param strParameter 要验证的字符串
* @param limitLength 验证的长度
* @return 符合长度ture 超出范围false
*/
public boolean validateStrByLength(String strParameter , int limitLength)
{
int temp_int=0;
byte[] b=strParameter.getBytes();
for(int i=0 ; i<b.length ; i++)
{
if(b[i]>=0)
{
temp_int=temp_int+1;
}
else
{
temp_int=temp_int+2;
i++;
}
}
if(temp_int > limitLength)
{
return false;
}
else
{
return true;
}
}
* 功能:验证字符串长度是否符合要求,一个汉字等于两个字符
* @param strParameter 要验证的字符串
* @param limitLength 验证的长度
* @return 符合长度ture 超出范围false
*/
public boolean validateStrByLength(String strParameter , int limitLength)
{
int temp_int=0;
byte[] b=strParameter.getBytes();
for(int i=0 ; i<b.length ; i++)
{
if(b[i]>=0)
{
temp_int=temp_int+1;
}
else
{
temp_int=temp_int+2;
i++;
}
}
if(temp_int > limitLength)
{
return false;
}
else
{
return true;
}
}
本文介绍了一个用于验证字符串长度是否符合指定要求的方法,该方法能够正确处理包含汉字的字符串,一个汉字被视为两个字符。
5325

被折叠的 条评论
为什么被折叠?



