str = ' AAA|+aaa |BBB|+ccc DDD|ddd+EEE '
print str,'len = ',len(str)
print '\n'
x = raw_input('plz input the separator:')
a=b=n=0
while a <= len(str):
while str[a] == x :
a= a + 1
n = a
if a == len(str):
break
if a == len(str):
break
while str[a] != x :
a = a + 1
m = a
if a == len(str):
break
print 'n=',n,'m=',m,str[n:m]
if a == len(str):
break
先写在这里,每个while 都用了break才能退出,不然运行会因为超过index数报错。
转载于:https://blog.51cto.com/374721/1600542