//计算包含英文与汉字的字符串长度 function countCharacters(str){ var totalCount = 0; for (var i=0; i<str.length; i++) { var c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { totalCount++; }else { totalCount+=2; } } return totalCount; } //计算字符串中汉字长度 function countChineseCharacterLen(str){ var totalCount = 0; for (var i=0; i<str.length; i++) { var c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {} else { totalCount++; } } return totalCount; } //计算字符窜中英文字符长度 function countEnglishCharacterLen(str){ var totalCount = 0; for (var i=0; i<str.length; i++) { var c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { totalCount++; } } return totalCount; }
|
评论