如果第二个参数 bUnicode255For1 === true,则所有字符长度为 1
否则如果字符 Unicode 编码 > 255 则长度为 2
function strLength(s, bUnicode255For1) {
var count=
0
;
if
(bUnicode255For1 ===
true
)
{
return
s.length;
}
for
(var i=
0
;i<s.length;i++)
{
if
(s.charCodeAt(i)>
255
)
{
count=count+
2
;
}
else
count+=
1
;
}
return
count;
}
|