做個筆記,省的每次都忘記XD
//被搜尋的字串
str1=”abcgdefgggg”
//關鍵字
key=”gg”
document.write(CountKeyword(str1,key));
function CountKeyword(str,keyword){
index = 0;
count = 0;
while (index!=-1){
index = str.indexOf(keyword,index);
if (index!=-1){
index = index + keyword.length;
count++;
}
}
return count;
}