Thursday 12 December 2013

Count string occurrence in string

This is from a javascript question on StackOverflow.

You just have to see rebolek's answer here to know what we are doing. The function below is the same with minor modifications.

Code:

Usage:

Keep in mind, though that this code will not work when you have case-sensitivity as a concern. Also, repeated strings will be an issue (e.g. In "aaa", you will get 1 occurrence of "aa" instead of 2).

No comments:

Post a Comment