{"id":485,"date":"2013-06-09T09:38:58","date_gmt":"2013-06-09T01:38:58","guid":{"rendered":"http:\/\/www.kiccleaf.com\/?p=485"},"modified":"2013-06-09T09:39:21","modified_gmt":"2013-06-09T01:39:21","slug":"python-%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%93%8d%e4%bd%9c%e3%80%90%e8%bd%ac%e3%80%91","status":"publish","type":"post","link":"http:\/\/www.kiccleaf.com\/?p=485","title":{"rendered":"Python \u5b57\u7b26\u4e32\u64cd\u4f5c\u3010\u8f6c\u3011"},"content":{"rendered":"<p>Python \u5b57\u7b26\u4e32\u64cd\u4f5c\uff08string\u66ff\u6362\u3001\u5220\u9664\u3001\u622a\u53d6\u3001\u590d\u5236\u3001\u8fde\u63a5\u3001\u6bd4\u8f83\u3001\u67e5\u627e\u3001\u5305\u542b\u3001\u5927\u5c0f\u5199\u8f6c\u6362\u3001\u5206\u5272\u7b49\uff09<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n\r\n\u53bb\u7a7a\u683c\u53ca\u7279\u6b8a\u7b26\u53f7  \r\ns.strip() .lstrip() .rstrip(',')   \r\n \r\n\u590d\u5236\u5b57\u7b26\u4e32  \r\n#strcpy(sStr1,sStr)   \r\nsStr= 'strcpy'   \r\nsStr = sStr  \r\nsStr= 'strcpy'   \r\nprint sStr   \r\n \r\n\u8fde\u63a5\u5b57\u7b26\u4e32  \r\n#strcat(sStr1,sStr)   \r\nsStr= 'strcat'   \r\nsStr = 'append'   \r\nsStr+= sStr   \r\nprint sStr  \r\n \r\n\u67e5\u627e\u5b57\u7b26  \r\n#strchr(sStr1,sStr)   \r\nsStr= 'strchr'   \r\nsStr = 's'   \r\nnPos = sStr1.index(sStr)   \r\nprint nPos   \r\n \r\n\u6bd4\u8f83\u5b57\u7b26\u4e32  \r\n#strcmp(sStr1,sStr)   \r\nsStr= 'strchr'   \r\nsStr = 'strch'   \r\nprint cmp(sStr1,sStr)  \r\n \r\n\u626b\u63cf\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u6307\u5b9a\u7684\u5b57\u7b26  \r\n#strspn(sStr1,sStr)   \r\nsStr= '1345678'   \r\nsStr = '456'   \r\n#sStrand chars both in sStrand sStr   \r\nprint len(sStrand sStr)  \r\n \r\n\u5b57\u7b26\u4e32\u957f\u5ea6  \r\n#strlen(sStr1)   \r\nsStr= 'strlen'   \r\nprint len(sStr1)   \r\n \r\n\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5927\u5c0f\u5199\u8f6c\u6362  \r\n#strlwr(sStr1)   \r\nsStr= 'JCstrlwr'   \r\nsStr= sStr1.upper()   \r\n#sStr= sStr1.lower()   \r\nprint sStr  \r\n \r\n\u8ffd\u52a0\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u7b26\u4e32  \r\n#strncat(sStr1,sStr,n)   \r\nsStr= '1345'   \r\nsStr = 'abcdef'   \r\nn = 3 \r\nsStr+= sStr&#x5B;0:n]   \r\nprint sStr  \r\n \r\n\u5b57\u7b26\u4e32\u6307\u5b9a\u957f\u5ea6\u6bd4\u8f83  \r\n#strncmp(sStr1,sStr,n)   \r\nsStr= '1345'   \r\nsStr = '13bc'   \r\nn = 3 \r\nprint cmp(sStr1&#x5B;0:n],sStr&#x5B;0:n])   \r\n \r\n\u590d\u5236\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u7b26  \r\n#strncpy(sStr1,sStr,n)   \r\nsStr= ''   \r\nsStr = '1345'   \r\nn = 3 \r\nsStr= sStr&#x5B;0:n]   \r\nprint sStr  \r\n \r\n\u5c06\u5b57\u7b26\u4e32\u524dn\u4e2a\u5b57\u7b26\u66ff\u6362\u4e3a\u6307\u5b9a\u7684\u5b57\u7b26  \r\n#strnset(sStr1,ch,n)   \r\nsStr= '1345'   \r\nch = 'r'   \r\nn = 3 \r\nsStr= n * ch + sStr1&#x5B;3:]   \r\nprint sStr  \r\n \r\n\u626b\u63cf\u5b57\u7b26\u4e32  \r\n#strpbrk(sStr1,sStr)   \r\nsStr= 'cekjgdklab'   \r\nsStr = 'gka'   \r\nnPos = -1 \r\nfor c in sStr1:   \r\n     if c in sStr:   \r\n         nPos = sStr1.index(c)   \r\n         break   \r\nprint nPos   \r\n \r\n\u7ffb\u8f6c\u5b57\u7b26\u4e32  \r\n#strrev(sStr1)   \r\nsStr= 'abcdefg'   \r\nsStr= sStr1&#x5B;::-1]   \r\nprint sStr  \r\n \r\n\u67e5\u627e\u5b57\u7b26\u4e32  \r\n#strstr(sStr1,sStr)   \r\nsStr= 'abcdefg'   \r\nsStr = 'cde'   \r\nprint sStr1.find(sStr)   \r\n \r\n\u5206\u5272\u5b57\u7b26\u4e32  \r\n#strtok(sStr1,sStr)   \r\nsStr= 'ab,cde,fgh,ijk'   \r\nsStr = ','   \r\nsStr= sStr1&#x5B;sStr1.find(sStr) + 1:]   \r\nprint sStr  \r\n \u6216\u8005   \r\ns = 'ab,cde,fgh,ijk'   \r\nprint(s.split(','))   \r\n \r\n\u8fde\u63a5\u5b57\u7b26\u4e32  \r\ndelimiter = ','   \r\nmylist = &#x5B;'Brazil', 'Russia', 'India', 'China']   \r\nprint delimiter.join(mylist)   \r\nPHP \u4e2d addslashes \u7684\u5b9e\u73b0  \r\ndef addslashes(s):   \r\n     d = {'&quot;':'\\\\&quot;', &quot;'&quot;:&quot;\\\\'&quot;, &quot;&#92;&#48;&quot;:&quot;\\\\&#92;&#48;&quot;, &quot;\\\\&quot;:&quot;\\\\\\\\&quot;}   \r\n    return ''.join(d.get(c, c) for c in s)   \r\ns = &quot;John 'Johny' Doe (a.k.a. \\&quot;Super Joe\\&quot;)\\\\&#92;&#48;&quot;   \r\nprint s   \r\nprint addslashes(s)   \r\n \r\n\u53ea\u663e\u793a\u5b57\u6bcd\u4e0e\u6570\u5b57  \r\ndef OnlyCharNum(s,oth=''):   \r\n     s = s.lower();   \r\n    fomart = 'abcdefghijklmnopqrstuvwxyz013456789'   \r\n    for c in s:   \r\n        if not c in fomart:   \r\n             s = s.replace(c,'');   \r\n     return s;   \r\nprint(OnlyStr(&quot;a000 aa-b&quot;)) \r\n<\/pre>\n<p>\u8f6c\u81ea\uff1ahttp:\/\/wangwei007.blog.51cto.com\/68019\/903426<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5b57\u7b26\u4e32\u64cd\u4f5c\uff08string\u66ff\u6362\u3001\u5220\u9664\u3001&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.kiccleaf.com\/?p=485\">Continue reading<span class=\"screen-reader-text\">Python \u5b57\u7b26\u4e32\u64cd\u4f5c\u3010\u8f6c\u3011<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3,"footnotes":""},"categories":[20],"tags":[95,46],"class_list":["post-485","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-46","entry"],"views":5739,"_links":{"self":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=485"}],"version-history":[{"count":0,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}