//문자열 length구하기
function getByteLength(val)
{
var tmplen = 0;
for (var i = 0; i < val.length; i++)
{
if (val.charCodeAt(i) > 127)
tmplen += 2;
else
tmplen++;
}
return tmplen;
}



아래 링크에서 개선된 방식 비교 (속도 빠름)
http://programmingsummaries.tistory.com/239


function getByteLength(s,b,i,c){
    for(b=i=0;c=s.charCodeAt(i++);b+=c>>11?3:c>>7?2:1);
    return b;
}


+ Recent posts