Skip to content

Instantly share code, notes, and snippets.

@ensky
Created May 6, 2012 17:41
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 ensky/2623458 to your computer and use it in GitHub Desktop.
Save ensky/2623458 to your computer and use it in GitHub Desktop.
JS 中文字長度偵測
// 中文字會算長度2,英文字算長度1
String.prototype.Blength = function() {
var arr = this.match(/[^\x00-\xff]/ig);
return arr == null ? this.length : this.length + arr.length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment