2005-10-20

 

Get UTF-8 Char length in JavaScript

function getUTF8Len(s) {

var len = 0;

for (var i = 0; i <>

c = s.charCodeAt(i);

if (c <= 0x7f) {

len++;

} else if (c >= 0x80 && c <= 0x7ff) {

len+=3;

} else {

len+=2;

}

} return len;

}


This page is powered by Blogger. Isn't yours?