Home >Backend Development >PHP Tutorial > 判断字符长度解决方法

判断字符长度解决方法

WBOY
WBOYOriginal
2016-06-13 13:14:58900browse

判断字符长度
function checkLength(str)
{
var i,sum;
sum=0;
for(i=0; i {
if ((str.charCodeAt(i)>=0) && (str.charCodeAt(i) sum = sum + 1;
else
sum = sum + 2;
}
return sum;
}

里面的(str.charCodeAt(i)>=0) && (str.charCodeAt(i)
------解决方案--------------------
(str.charCodeAt(i)>=0) && (str.charCodeAt(i)表示的是一个以Unicode 编码为基准的字符
大于255好像是表示一个字,占两位

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn