Get string length - Node.js String

Node.js examples for String:String Value

Description

Get string length

Demo Code

function lengthOf(str){
  var ret = 0;//from w w  w  .j  ava  2s  .c  o  m
  for(var e = 0;e< str.length;e++){
    if(/[^\x00-\xff]/.test(str.charAt(e))){
      ret+=2;
    }else
      ret+=1;
  }
  return ret;
}

Related Tutorials