Skip to content

Instantly share code, notes, and snippets.

@lushijie
Last active December 28, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lushijie/5d6d1b09d1424243c95fedc12462b6e4 to your computer and use it in GitHub Desktop.
Save lushijie/5d6d1b09d1424243c95fedc12462b6e4 to your computer and use it in GitHub Desktop.
返回字符串的实际长度
// 返回字符串的实际长度, 一个汉字算2个长度
String.prototype.strlen = function () {
return this.replace(/[^\x00-\xff]/g, "**").length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment