Last active
August 29, 2015 14:11
计算字符串长度
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 | |
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