occurences of substring in a String python
python program to get a String and Substring and count the occurrence of substring in string.
Sample Input 1 :
entertainment en
Sample Output 1 :
2
Try your Solution
Strongly recommended to Solve it on your own, Don't directly go to the solution given below.
#write your code here
Program or Solution
s1=input("Enter a String:")
s2=input("Enter Substring:")
count=0
for i in range(0,len(s1)-len(s2)+1):
j=0
b=0
if(s1[i]==s2[j]):
k=i
while(j<len(s2)):
if(s1[k]!=s2[j]):
b=1
break
j=j+1
k=k+1
if(b==0):
count+=1
print(count)
Program Explanation
check whether first character of sub string is equal to any character in string.
If it is equal, then check remaining characters are equal to the characters in substring.
else move to next character.
Comments
Related Programs
- length of the string in python
- find a character in a String Python
- occurences of character in string python
- lowercase to uppercase in python
- uppercase to lowercase in python
- python count vowels in string
- Compare two Strings in python
- find vowels in string python
- find substring in string pyhton
- Reverse the String in python
- string Palindronme in python
- Remove the spaces in String python
- Remove the Vowels in String Python
coming Soon
coming Soon