JS中的字符串
//字符串常用属性 var str = "ancdfrgb"; document.write(str.length + "<br>");//计算字符串的长度 document.write(str.charAt(3) + "<br>");//输出指定的字符,超出字符串则输出空 document.write(str.concat("hhjkk", "kkkk") + "<br>");//字符串拼接 document.write(str.indexOf("c") + "<br>");//返回字符所在的长度数 var gg = "jjkkii"; if (gg.indexOf("jj") == 0) {//替换字符串 gg = gg.replace("jj", "bb"); } else { document.write("不存在!"); } document.write(gg); var str1 = "gopisigvsgvbksefh,alevnaknval"; document.write(str1.slice(5, 10));//输出指定区域的字符串 var str2 = "a,c,v,f,h,t,u,r"; document.write(str2 + "<br>"); var arr1 = str2.split(",");//切割字符串,并组成一个分组 for (var i = 0; i < arr1.length; i++) { document.write(arr1[i]);} var str5 = "jjjjjkkkfsvxlvmslvmsv"; var str2 = str5.substr(5);//从第五个开始输出后面的所有数 var str3 = str5.substr(5, 5);//从后往前输出指定区域输出字符串 var str4 = str5.substring(5, 5);//从前往后输出指定区域输出字符串 document.write(str2 + "<br>"); document.write(str4 + "<br>"); document.write(str3);