如何统计字符串中出现的字符串?如何计算特定字符串在另一个字符串中发生的次数。例如,这就是我在Javascript中试图做的:var temp = "This is a string.";alert(temp.count("is")); //should output '2'
3 回答

繁花不似锦
TA贡献1851条经验 获得超4个赞
function countInstances(string, word) { return string.split(word).length - 1;}
添加回答
举报
0/150
提交
取消