How can I count the number of times a particular string occurs in another string. For example, this is what I am trying to do in Javascript:
var temp = "This is a string.";
alert(temp.count("is")); //should output '2'
How can I count the number of times a particular string occurs in another string. For example, this is what I am trying to do in Javascript:
var temp = "This is a string.";
alert(temp.count("is")); //should output '2'
Use get_occurrence(varS,string) to find occurrence of both characters and string in a String.
You can use
match
to define such function:The non-regex version:
Try it
Just code-golfing Rebecca Chernoff's solution :-)