|
|
发表于 2019-3-26 13:20:45
|
显示全部楼层
txt = "I asked Sir Andrew who he was,2 and he answered \
impatiently: \"00Sir Nancy and 0I are Knaves!\" 66 54 88 !\
impatiently: \"22Sir Nancy and I 2are Knaves!\" 76 66 35 !\
impatiently: \"55Sir Nancy and5 I are Knaves!\" 54 66 98 !"
print('--------------')
print(txt)
str0 = txt.split('!')
print('--------------')
print('处理前分割效果')
for s in str0:
print(s)
#处理字符串
for i in range(len(str0) - 1):
print(i)
count = 0;
for s in str0[i]:
if s == "\"":
count += 1
if((count % 2 == 1) and str0[i+1].startswith('"')):
str0[i] = str0[i] + '"'
str0[i+1] = str0[i+1][1:]
print('--------------')
print('处理后分割效果')
for s in str0:
print(s) |
|