goes to space and special symbols

 s.strip ().Lstrip (),.Rstrip (',') 

Python strip () method is used to remove the characters specified by the end of the string (the default is space).

 #strcpy copy the string (sStr1, sStr2) sStr1 ='strcpy'sStr2 = sStr1 sStr1 ='strcpy2' print sStr2

 #strcat connection string (sStr1, sStr2) sStr1 ='strcat'sStr2 ='append' sStr1 = sStr2 print sStr1

 #strchr find the characters (sStr1, sStr2) # < 0 for sStr1 not found ='strchr'sStr2 ='s' nPos = sStr1.index (sStr2) print nPos

 #strcmp comparison string (sStr1, sStr2) sStr1 ='strchr'sStr2 ='strch' print CMP (sStr1, sStr2) 

scan a string containing the specified character of

 #strspn (sStr1, sStr2) sStr1 ='12345678'sStr2 ='456' #sStr1 and chars both in sStr1 and sStr2 print len (sStr1 and sStr2) 

 #strlen string length (sStr1) = sStr1 'strlen'print len (sStr1) 

in the string case conversion

 #strlwr (sStr1) sStr1 ='JCstrlwr' sStr1 = sStr1.upper (#sStr1) = sStr1.lower (print) sStr1

appends a specified length string

 #strncat (sStr1, sStr2, n) sStr1 ='12345'sStr2 ='abcdef' n = 3 sStr1 = sStr2[0:n] print sStr1

 #strncmp specifies the length of the string (sStr1, sStr2, n) sStr1 ='12345'sStr2 ='123bc' n = 3 print CMP (sStr1[0:n], sStr2[0:n]) 

 a copy of the specified length character of #strncpy (sStr1, sStr2, n) sStr1 = 'sStr2 ='12345' n = 3 sStr1 = sStr2[0:n] print sStr1

will replace n character string before the specified character of

 #strnset (sStr1, CH, n) sStr1 ='12345'ch ='r' n = 3 sStr1 = n * ch SStr1[3:] print sStr1


 #strpbrk scan string (sStr1, sStr2) sStr1 ='cekjgdklab'sStr2 ='gka' nPos = -1 for C in sStr1: if C in sStr2: nPos = sStr1.index (c) break print nPos

 #strrev flip string (sStr1) sStr1 ='abcdefg'sStr1 = sStr1[-1] print sStr1


search string

 #strstr (sStr1, sStr2) sStr1 ='abcdefg' sStr2 ='cde'print sStr1.find (sStr2) 

 #strtok string partition (sStr1, sStr2) sStr1 ='ab, CDE, FGH, ijk' sStr2 = 'sStr1' = sStr1[sStr1.find (sStr2) + 1:] print sStr1 # or S ='ab, CDE, FGH ijk', print (s.split (' ')) 

 connection string delimiter =' mylist '= ['Brazil','Russia','India','China'] print delimiter.join (mylist) 

 def addslashes addslashes 


PHP (s): D = {'' ',' ': trailing' "": "'re", "", "\", " " "return "}''.join (d.get (C, c) for C in s) s = "John'Johny'Doe (a.k.a." Super Joe ") \ s print addslashes print (s)

displays only letters and numbers

 def OnlyCharNum (s, oth=''): S2 = s.lower (fomart ='abcdefghijklmnopqrstuvwxyz0123456789'); for C in s2: if not C in fomart: s (c = s.replace return; s;' '), print (OnlyStr (" a000 aa-b ") 



string STR =' print str[0:3] # from first to third characters: print str[] # string all the character print str[6:] # intercepted seventh characters at the end: print str[-3] # interception from scratch to start Before the last third characters of print str[2] # intercepted third characters print str[-1] # interception countdown to the first character of the print: str[: -1] # before creating a contrast with the original string string sequence print str[-3:-1] # intercepted third countdown countdown and the first character of the print str[-3:] # intercepted third countdown to the end: print str[-5:-3] # what specific reverse interception, don't understand? This article is introduced in this article,

, and I hope you will support a lot of scripting home in the future.

This concludes the body part

This paper fixed link:http://www.script-home.com/python-string-manipulation-string-replacement-deletion-interception-replication-connection-comparison-lookup-inclusion-case-and-partition-etc.html | Script Home | +Copy Link

Article reprint please specify:Python string manipulation (string replacement, deletion, interception, replication, connection, comparison, lookup, inclusion, case, and partition, etc.) | Script Home

You may also be interested in these articles!