Counts how many times a substring occurs within a string.
The input string.
The substring to count.
Number of times sub occurs in str.
sub
str
0
countSubstring("lololol", "lo"); // 3countSubstring("aaaaa", "a"); // 5countSubstring("hello", "z"); // 0 Copy
countSubstring("lololol", "lo"); // 3countSubstring("aaaaa", "a"); // 5countSubstring("hello", "z"); // 0
Counts how many times a substring occurs within a string.