I have a python string like
superstring = '/aaa/bbb/ref/ccc/ddd/ref/eee/fff/' substring1 = '/' substring2 = '/ref/'
I would like to count the number of occurrences of substring1
and substring2
inside the superstring
.
How can I achieve that?
Use .count()
function for this purpose. The commands
superstring.count('/') superstring.count(substring2)
will return
9
2