用字符串的split方法将其分为数组,数组的length-1就是字符的出现次数。代码修改为JavaScript如下:
function test(){
var str = "www.netsuite.com";
alert(str.split("c").length-1);
alert(str.split("w").length-1);
}
用字符串的split方法将其分为数组,数组的length-1就是字符的出现次数。代码修改为JavaScript如下:
function test(){
var str = "www.netsuite.com";
alert(str.split("c").length-1);
alert(str.split("w").length-1);
}
转载于:https://www.cnblogs.com/backuper/archive/2009/05/10/1453705.html