function getLen(str) { var name = ''; var len = 0; var strlen = 0; for (var i = 0; i < str.length; i++) { charCode = str.charCodeAt(i); if (charCode >= 0 && charCode <= 128) len += 1; else len += 2; } return len; }
getLen('家好就abc') //9
getLen('abcdefg') //7