Remove spaces and special symbols
s.strip().lstrip().rstrip(',')
Copy string
#strcpy(sStr1,sStr2)sStr1 = 'strcpy'sStr2 = sStr1sStr1 = 'strcpy2'print sStr2
Connection string
#strcat(sStr1,sStr2)sStr1 = 'strcat'sStr2 = 'append'sStr1 += sStr2print sStr1
Search for characters
# Strchr (sstr1, SSTR2) #<0 indicates that sstr1 = 'strchr 'SSTR2 = 's' NPOs = sstr1.index (SSTR2) print NPOs is not found
Comparison string
#strcmp(sStr1,sStr2)sStr1 = 'strchr'sStr2 = 'strch'print cmp(sStr1,sStr2)
Whether the scan string contains specified characters
#strspn(sStr1,sStr2)sStr1 = '12345678'sStr2 = '456'#sStr1 and chars both in sStr1 and sStr2print len(sStr1 and sStr2)
String Length
#strlen(sStr1)sStr1 = 'strlen'print len(sStr1)
Converts the uppercase and lowercase letters in a string.
#strlwr(sStr1)sStr1 = 'JCstrlwr'sStr1 = sStr1.upper()#sStr1 = sStr1.lower()print sStr1
Append a string of the specified length
#strncat(sStr1,sStr2,n)sStr1 = '12345'sStr2 = 'abcdef'n = 3sStr1 += sStr2[0:n]print sStr1
String Length comparison
#strncmp(sStr1,sStr2,n)sStr1 = '12345'sStr2 = '123bc'n = 3print cmp(sStr1[0:n],sStr2[0:n])
Copy characters of the specified length
#strncpy(sStr1,sStr2,n)sStr1 = ''sStr2 = '12345'n = 3sStr1 = sStr2[0:n]print sStr1
Replaces the first n characters of a string with the specified characters.
#strnset(sStr1,ch,n)sStr1 = '12345'ch = 'r'n = 3sStr1 = n * ch + sStr1[3:]print sStr1
Scan string
#strpbrk(sStr1,sStr2)sStr1 = 'cekjgdklab'sStr2 = 'gka'nPos = -1for c in sStr1: if c in sStr2: nPos = sStr1.index(c) breakprint nPos
Flip string
#strrev(sStr1)sStr1 = 'abcdefg'sStr1 = sStr1[::-1]print sStr1
Search for strings
#strstr(sStr1,sStr2)sStr1 = 'abcdefg'sStr2 = 'cde'print sStr1.find(sStr2)
Split string
# Strtok (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)
Implementation of addslashes in PHP
def addslashes(s): d = {'"':'\\"', "'":"\\'", "\0":"\\\0", "\\":"\\\\"} return ''.join(d.get(c, c) for c in s) s = "John 'Johny' Doe (a.k.a. \"Super Joe\")\\\0"print sprint addslashes(s)
Show only letters and numbers
def OnlyCharNum(s,oth=''): s2 = s.lower(); fomart = 'abcdefghijklmnopqrstuvwxyz0123456789' for c in s2: if not c in fomart: s = s.replace(c,''); return s; print(OnlyStr("a000 aa-b"))