Javascript String count()

Description

Javascript String count()

String.prototype.count = function()
{
 var value = 0;/*from w w  w  .j  a  v a 2s .c o m*/
 var i = this.length;
 while (i--)
 {
  var c = this.charCodeAt(i);
  value += c < 128 ? 1 : (c < 2048 ? 2 : 3);
 }
 return value;
}



PreviousNext

Related