Find a string

  • + 0 comments
    def count_substring(string, sub_string):
        count = 0
        next_index = 0
        
        while True:
            found_index = string.find(sub_string, next_index)
            if found_index >= 0:
                count += 1
                next_index = found_index + 1
            else:
                return count