diff --git a/Utils/oLib.js b/Utils/oLib.js index aae9a43..2a47dbf 100644 --- a/Utils/oLib.js +++ b/Utils/oLib.js @@ -23,6 +23,32 @@ { 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