Find a string

  • + 0 comments

    sliding through string looking using index and counting occurences + comments for debug

        a = string
        b = sub_string
        counter = 0
        slider = 0
        while slider <= len(a):
            #print(f"looking for substring {b} in string {a} starting from position {slider}")
            if a.find(b,slider) > -1:
                #print (f"found substring {b} at position {a.find(b,slider)}")
                slider = a.find(b,slider)
                counter += 1
            slider +=1
        return counter