function getLen(sString)

{
var sStr,iCount,i,strTemp ; 
iCount = 0 ;
sStr = sString.split("");
for (i = 0 ; i < sStr.length ; i ++)
{
strTemp = escape(sStr[i]);
if (strTemp.indexOf("%u",0) == -1)
{
iCount = iCount + 1 ;
}
else
{
iCount = iCount + 2 ;
}
}
return iCount ;
} 
function getLen( str)
{
var totallength=0; for (var i=0;i<str.length;i++)
{
var intCode=str.charCodeAt(i); if (intCode>=0&&intCode<=128)
{
totallength=totallength+1; //非中文单个字符长度加 1
}
else
{
totallength=totallength+2; //中文字符长度则加 2
}
} //end for
return totallength;
}
205

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



