Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Count Substring Occurrences by marko.milevski
def count_occurrences(text: str, sub: str) -> int:
text_lower = text.lower()
sub_lower = sub.lower()
count = 0
start = 0
while True:
index = text_lower.find(sub_lower, start)
if index == -1:
break
count += 1
start = index + 1
return count
Oct. 23, 2025
Comments: