giai ho tui

*/
function occurrences(string, subString, allowOverlapping) {
string += “”;
subString += “”;
if (subString.length <= 0) return (string.length + 1);
var n = 0,
pos = 0,
step = allowOverlapping ? 1 : subString.length;
while (true) {
pos = string.indexOf(subString, pos);
if (pos >= 0) {
++n;
pos += step;
} else break;
}
return n;
}

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar

Facebook