Created
May 6, 2012 17:41
-
-
Save ensky/2623458 to your computer and use it in GitHub Desktop.
JS 中文字長度偵測
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 中文字會算長度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