字符串查找,不使用indexOf,substr,正则,substring,contain,slice等现成的方法
程序员文章站
2022-06-09 20:06:44
...
var str = '12', strAll = '4512563';
function isContain(a, b) {
var aL = a.length,bL = b.length,index = -1;
for (var i = 0; i < bL - aL; i++) {
if (b.slice(i, i + aL) == str) {
index = i
}
}
return index;
}
isContain(str, strAll)