首页 > 其他 > 详细

使用indexOf()算出长字符串中包含多少个短字符串

时间:2014-03-11 05:00:45      阅读:340      评论:0      收藏:0      [点我收藏+]

function countInstance(mainStr,srchStr){
var count = 0;
var offset = 0;// 搜索的起始位置
do{
offset = mainStr.indexOf(srchStr,offset);
count += (offset != -1)? 1:0;
}while(offset++ != -1);
return count;

}

alert(countInstance("wwweeewwwweee",‘we‘));  //2

使用indexOf()算出长字符串中包含多少个短字符串,布布扣,bubuko.com

使用indexOf()算出长字符串中包含多少个短字符串

原文:http://www.cnblogs.com/xiaowuge/p/3591512.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!