手写split功能
def split_new(stringstr, charstr):
"""
:param stringstr: 要分割的串
:param charstr: 按该串分割
:return: 返回分割后的list
"""
res = []
lenchar = len(charstr)
while 1:
index = stringstr.find(charstr) #如果没有找到目标字符串,返回-1
if index == -1:
res.append(stringstr)
return res
else:
res.append(stringstr[:index]) #将目标字符串前的字符串存下来
stringstr = stringstr[index+lenchar:] 新字符串截取自目标字符串以后的
if __name__=="__main__":
print(split_new("ABCDEFGAA@@ABCDEFGA@@ABCDEFG", "ZZZ"))