想要截取字符串前几位与后几位,主要代码如下 截取字符串前几位 var disName ='开心一族漂亮家园'; var shortName = disName.substring(0,5); console.log(shortName);//打印结果:开心一族漂 截取字符串后几位 var disName ='开心一族漂亮家园'; var disLength = disName.length; var shortName = disName.substring(disLength-2,disLen
js截取字符串并且区分汉字字母,一个汉字辨别为两个字节. function substr(str, len) { if (!str || !len) { return ''; } // 预期计数:中文2字节,英文1字节 var a = 0; // 循环计数 var i = 0; // 临时字串 var temp = ''; for (i = 0; i < str.length; i++) { if (str.charCodeAt(i) > 255) { // 按照预期计数增加2 a += 2;
<script> function subString(str, len, hasDot) { var newLength = 0; var newStr = ""; var chineseRegex = /[^\x00-\xff]/g; var singleChar = ""; var strLength = str.replace(chineseRegex,"**").length; for(var i = 0;i < st
js MD5加密后的字符串 <script language="JavaScript"> /***************************************************************************** * md5.js * * A JavaScript implementation of the RSA Data Security, Inc. MD5 * Message-Digest Algorithm. * * C