使用indexOf()算出长字符串中包含多少个短字符串
2014-03-10 12:14
288 查看
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
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
相关文章推荐
- JS判断字符串是否包含某字符串 indexOf()方法使用
- JS判断字符串是否包含某字符串 indexOf()方法使用
- javascript 判断字符串是否包含某字符串及indexOf使用示例
- JS判断字符串是否包含某字符串 indexOf()方法使用
- JS判断字符串是否包含某字符串 indexOf()方法使用
- String 是否包含该字符串,使用 contains 和 indexOf 的区别
- JS判断字符串是否包含某字符串 indexOf()方法使用
- C#中查询字符串中是否包含指定字符/字符串,使用IndexOf还是Contains?
- C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?
- javascript 判断字符串是否包含某字符串及indexOf使用示例
- JS判断字符串是否包含某字符串 indexOf()方法使用
- C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?
- JS判断字符串包含(indexOf)
- 使用正则表达式找出不包含特定字符串的条目
- 有一字符串,包含数字与字母,编程去除数字。(1、要求在原字符串中操作,2、使用指针处理)
- 有一字符串,包含数字与字母,编程去除数字。要求:1要求在原字符串中操作 2、使用指针处理
- (转)使用零宽断言来匹配不包含连续字符串的行
- PowerShell中查找字符串位置的IndexOf函数使用实例
- 使用MessageFormat处理包含占位符的字符串
- (本程序功能:字符串A中找出包含字符串B中所有字符的位置并输出) 在使用全局变量m的时候,输出错误的结果,而用下面局部变量M就没问题。