string.count(substring,start,end)
Parameter | Description |
---|---|
substring | string whose count is to be found. |
start | optional. starting index within the string where search starts. |
end | Optional. ending index within the string where search ends. |
count() method returns the number of occurrences of the substring in the given string.
# define stringstring = "vishal is working in cppsecrets"substring = "is"count = string.count(substring)# print countprint("The count is:", count)
# define stringstring = "vishal is working in cppsecrets"substring = "i"# count after first 'i' and before the last 'i'count = string.count(substring, 8, 25)# print countprint("The count is:", count)
**********END OF ARTICLE **********
Comments