自己設計一個Python分割函數,根據不同字符,其中的點號可以改為其他符號
**********************************************************
s = 'xbc..w1z2x......yd3c....eeff'
print(s)
#s = s.strip()
#print(s)
sep = '..'
def my_split(src, sep):
a = s.find(sep)
w1 = s[:a]
print(w1)
b = a
i = 0
n = len(sep)
while b <= len(s) and b != -1:
while s[a:a + n] == sep:
a = a + n
b = s.find(sep, a)
if b != -1:
print(s[a:b])
else:
print(s[a:])
a = b
i = i + 1
print('enter my_split')
my_split(s, sep)
print('=============================')
my_split(s, '.')
print('=============================')
my_split(s, '...')
print('leave my_split')
Python 的詳細介紹:請點這裡
Python 的下載地址:請點這裡