标签:style blog color io for cti
用到了就记下来,获得字符串字节长度,适用于汉字跟英文混合输入
1 function getBytesCount(str) 2 { 3 var bytesCount = 0; 4 if (str != null) 5 { 6 for (var i = 0; i < str.length; i++) 7 { 8 var c = str.charAt(i); 9 if (c.match(/[^\x00-\xff]/ig) != null) //全角 10 { 11 bytesCount += 2; 12 } 13 else 14 { 15 bytesCount += 1; 16 } 17 } 18 } 19 return bytesCount; 20 }
标签:style blog color io for cti
原文地址:http://www.cnblogs.com/mauiie/p/3857752.html