使用此函数能返回字符串中某个字符或字符串出现的次数其中mainStr为要查找的字符串subStr为要检查的字符串或字符
function countInstances(mainStr subStr)
{
var count = ;
var offset = ;
do
{
offset = mainStrindexOf(subStr offset);
if(offset != )
{
count++;
offset += subStrlength;
}
}while(offset != )
return count;
}