Programs on String Manipulation

1. write a program to read text and count total no. of lower case letters upper Case letters, digits,alphabets, special characters, Total Words .

text=input(“Enter Text”)
l=u=d=a=s=sp=0
for ch in text:
if ch.isalpha():
a+=1
if ch.islower():
l+=1
elif ch.isupper():
u+=1
elif ch.isdigit():
d+=1
elif ch.isspace():
sp+=1
else:
s+=1
print(‘Total Alphabets are :’,a)
print(‘Total Upper Case are :’,u)
print(‘Total Lower Case are :’,l)
print(‘Total Digits are :’,d)
print(‘Total Special Characters :’,s)
print(‘Total WORDS ARE :’,sp+1)

2. write a program to read text and capitalize first letter of each word

text=input(“Enter Text”)
L=[]
NW=””
L=text.split()
for ch in L:
NW+=ch.capitalize()+’ ‘
print(NW)

3. write a program to find sub string in a text given

text=input(“Enter Text”)
sub=input(“Enter sub string to find in Text”)
f=text.find(sub)
if f==-1:
print(sub,’ is not present ‘)
else:
print(sub,’ is present at ‘,f,’ position’)

4. write a program to check whether the given string is palindrome

str=input(“Enter Text”)
rev=str[::-1]
if str==rev:
print(str, ‘ is Palindrome’)
else:
print(str, ‘ is not Palindrome’)