mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-14 00:18:40 +00:00
Added substr_count
This commit is contained in:
parent
49589a115d
commit
4dff9197c6
|
|
@ -23,6 +23,32 @@
|
||||||
{
|
{
|
||||||
return str.replace(new RegExp("^[" + char + "]*"), '');
|
return str.replace(new RegExp("^[" + char + "]*"), '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jsOMS.substr_count = function(str, substr) {
|
||||||
|
str += '';
|
||||||
|
substr += '';
|
||||||
|
|
||||||
|
if (substr.length <= 0) {
|
||||||
|
return (str.length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let n = 0,
|
||||||
|
pos = 0,
|
||||||
|
step = substr.length;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
pos = str.indexOf(substr, pos);
|
||||||
|
|
||||||
|
if (pos >= 0) {
|
||||||
|
++n;
|
||||||
|
pos += step;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class finder
|
* Class finder
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user