say "the three truths".count("th")say "ababababab".count("abab")
User-created function:
func countSubstring(s, ss) { var re =Regex(ss.escape,'g') # 'g' for global var counter =0while (s =~ re) { ++counter }return counter}say countSubstring("the three truths","th")say countSubstring("ababababab","abab")