Quantcast
Channel: How to count string occurrence in string? - Stack Overflow
Viewing all articles
Browse latest Browse all 43

Answer by Diogo Arenhart for How to count string occurrence in string?

$
0
0

Try this:

function countString(str, search){    var count=0;    var index=str.indexOf(search);    while(index!=-1){        count++;        index=str.indexOf(search,index+1);    }    return count;}

Viewing all articles
Browse latest Browse all 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>