#python string Manipulation" "1. Copying Strings" "#strcpy (SSTR1,SSTR2)SSTR1 ='strcpy'SSTR2=SSTR1SSTR1='Strcpy2'PrintSSTR2" "2. Connection string" "#strcat (SSTR1,SSTR2)SSTR1 ='strcat'SSTR2='Append'SSTR1+=SSTR2PrintSSTR1" "3. Find characters" "#STRCHR (SSTR1,SSTR2)SSTR1 ='STRCHR'SSTR2='R'NPos=Sstr1.index (SSTR2)PrintNPos" "4. Comparing Strings" "#strcmp (SSTR1,SSTR2)SSTR1 ='STRCHR'SSTR2='Strch'PrintCMP (SSTR1,SSTR2)" "5. Whether the scanned string contains the specified characters" "#strspn (SSTR1,SSTR2)SSTR1 ='12345678'SSTR2='456'#SStr1 and chars both in SSTR1 and SSTR2PrintLen (sStr1 andsStr2)" "6. String length" "#strlen (SSTR1)SSTR1 ='strlen'PrintLen (SSTR1)" "7. Convert lowercase characters in a string to uppercase characters" "#strlwr (SSTR1)SSTR1 ='jcstrlwr'SSTR1=Sstr1.upper ()PrintSSTR1" "8. Append a string of the specified length" "#strncat (sstr1,sstr2,n)SSTR1 ='12345'SSTR2='abcdef'N= 3SSTR1+=Sstr2[0:n]PrintSSTR1" "9. String specifying length comparison" "#strncmp (sstr1,sstr2,n)SSTR1 ='12345'SSTR2='123BC'N= 3PrintCMP (Sstr1[0:n],sstr2[0:n])" "10. Copy characters of the specified length" "#strncpy (sstr1,sstr2,n)SSTR1 ="'SSTR2='12345'N= 3SSTR1=Sstr2[0:n]PrintSSTR1" "11. String comparisons, case insensitive" "#stricmp (SSTR1,SSTR2)SSTR1 ='ABCEFG'SSTR2='ABCEFG'PrintCMP (Sstr1.upper (), Sstr2.upper ())" "12. Replace the first n characters of a string with the specified character" "#Strnset (sstr1,ch,n)SSTR1 ='12345'CH='R'N= 3SSTR1= n * ch + sstr1[3:]PrintSSTR1" "13. Scan Strings" "#strpbrk (SSTR1,SSTR2)SSTR1 ='Cekjgdklab'SSTR2='Gka'NPos=-1 forCinchSSTR1:ifCinchSstr2:npos=Sstr1.index (c) BreakPrintNPos" "14. Flipping a string" "#Strrev (SSTR1)SSTR1 ='ABCDEFG'SSTR1= Sstr1[::-1]PrintSSTR1" "15. Finding Strings" "#strstr (SSTR1,SSTR2)SSTR1 ='ABCDEFG'SSTR2='CDE'PrintSstr1.find (SSTR2)" "16. Splitting a string" "#strtok (SSTR1,SSTR2)SSTR1 ='Ab,cde,fgh,ijk'SSTR2=','SSTR1= Sstr1[sstr1.find (SSTR2) + 1:]PrintSStr1
Use the while and for output string values:
>>> Stru ='abc'print(len (stru))while (i<len (Stru)): print(stru[i]) i+=1 ABC
for inch Range (0,len (stri)): Print (Stri[i]) ABCD
string manipulation in Python