Python script language,
Python string operations (string replacement, deletion, interception, replication, connection, comparison, search, inclusion, case-insensitive conversion, and Segmentation)
String Length
#strlen(sStr1) sStr= 'strlen' print len(sStr1) |
|
Connection string
#strcat(sStr1,sStr) sStr= 'strcat' sStr = 'append' sStr+= sStr print sStr |
Comparison string
#strcmp(sStr1,sStr) sStr= 'strchr' sStr = 'strch' print cmp(sStr1,sStr) |
Remove spaces and special symbols
s.strip() s.lstrip() s.rstrip(',') |
Copy string
#strcpy(sStr1,sStr) sStr= 'strcpy' sStr = sStr sStr= 'strcpy' print sStr |
|
Search for characters
#strchr(sStr1,sStr) sStr= 'strchr' sStr = 's' nPos = sStr1.index(sStr)print nPos |
Whether the scan string contains specified characters
#strspn(sStr1,sStr) sStr= '1345678' sStr = '456' #sStrand chars both in sStrand sStr print len(sStrand sStr) |
Converts the uppercase and lowercase letters in a string.
#strlwr(sStr1) sStr= 'JCstrlwr' sStr= sStr1.upper() #sStr= sStr1.lower() print sStr |
Append a string of the specified length
#strncat(sStr1,sStr,n) sStr= '1345' sStr = 'abcdef' n = 3 sStr+= sStr[0:n] print sStr |
String Length comparison
#strncmp(sStr1,sStr,n) sStr= '1345' sStr = '13bc' n = 3 print cmp(sStr1[0:n],sStr[0:n]) |
Copy characters of the specified length
#strncpy(sStr1,sStr,n) sStr= '' sStr = '1345' n = 3 sStr= sStr[0:n] print sStr |
Replaces the first n characters of a string with the specified characters.
#strnset(sStr1,ch,n) sStr= '1345' ch = 'r' n = 3 sStr= n * ch + sStr1[3:] print sStr |
Flip string
#strrev(sStr1) sStr= 'abcdefg' sStr= sStr1[::-1] print sStr |
Search for strings
#strstr(sStr1,sStr) sStr= 'abcdefg' sStr = 'cde' print sStr1.find(sStr) |
Scan string
#strpbrk(sStr1,sStr) sStr= 'cekjgdklab' sStr = 'gka' nPos = -1 for c in sStr1: if c in sStr: nPos = sStr1.index(c) break print nPos |
Split string
# Strtok (sStr1, sStr) sStr = 'AB, cde, fgh, ijk 'sstr =', 'sstr = sStr1 [sStr1.find (sStr) + 1:] print sStr or s = 'AB, cde, fgh, ijk' print (s. split (',')) |
Connection string
Delimiter = ', 'mylist = ['Brazil', 'Russia ', 'India', 'China'] print delimiter. implementation of addslashes in join (mylist) PHP def addslashes (s): d = {'"':'\\"',"'":"\\'", "\ 0": "\ 0", "\": "\"} return ''. join (d. get (c, c) for c in s) s = "John 'Johnny 'Doe (a.k. a. \ "Super Joe \") \ 0 "print s print addslashes (s) |
|
Show only letters and numbers
def OnlyCharNum(s,oth=''): s = s.lower(); fomart = 'abcdefghijklmnopqrstuvwxyz013456789' for c in s: if not c in fomart: s = s.replace(c,''); return s; print(OnlyStr("a000 aa-b"))
|
View comments