Skip to content

Instantly share code, notes, and snippets.

@xincici
Last active August 29, 2015 14:11
Show Gist options
  • Save xincici/9a80146233a66b24728b to your computer and use it in GitHub Desktop.
Save xincici/9a80146233a66b24728b to your computer and use it in GitHub Desktop.
计算字符串长度
//计算字符串长度,中文按2
function getStringLen(str) {
var cArr = str.match(/[^\x00-\xff]/ig);
return str.length + (cArr == null ? 0 : cArr.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment