python--替換特殊字元
阿新 • • 發佈:2019-01-04
替換特殊字元:將‘\'’替換為空格
def check_quoto(str, n): for i in range(len(str) - int(n)): npos_q = -1 npos_b = -1 while keys[i + int(n)].count('\'') > 0: npos_q = str[i + int(n)].find('\'') npos_b = str[i + int(n)].find(' ') keys[i + int(n)] = replaceString(str[i + int(n)], npos_q, ' ') if npos_q >= 0 or npos_b > 0: keys[i + int(n)] = '\'' + keys[i + int(n)] + '\'' return keys
def replaceString(string, num, replace):
string2 = ''
for i in range(len(string)):
if i == num:
string2 += replace
else:
string2 += string[i]
return string2