Pythonç¼ç¨ä¸å¯¹å符串è¿è¡æç´¢æ¥æ¾ï¼å¹¶è¿åå符ä½ç½®ï¼æ¡ä¾ä»£ç å¦ä¸ï¼
# multiple searches of a string for a substring
# using s.find(sub[ ,start[, end]])
#以ä¸é¢testè¿æ®µææ¬ä¸ºä¾
text = 'MSKSASPKEPEQLRKLFIGGLSFETTDESLRSAHFESSSYGSAGRRF'
##æ¥æ¾ä¸é¢ææ¬ä¸çSAå符串
search = 'SA'
start = 0
while True:
index = text.find(search, start)
# if search string not found, find() returns -1
# search is complete, break out of the while loop
if index == -1:
break
print( "%s found at index %d" % (search, index) )
# move to next possible start position
start = index + 1
//è¿è¡ç»æï¼
#SA found at index 3
#SA found at index 31
#SA found at index 41