Javascript String lengthB()

Description

Javascript String lengthB()


String.prototype.lengthB = function() {
 var b = 0, l = this.length;
 if (l) {//w  w w  .j  a  v a 2 s .  co m
  for (var i = 0; i < l; i++) {
   if (this.charCodeAt(i) > 255) {
    b += 2;
   } else {
    b += 1;
   }
  }
  return b;
 } else {
  return 0;
 }
};



PreviousNext

Related