定义:
def strfindall(zstr, xstr):
"""
查找字符串内所有字符起始位置\n
:param zstr: 被查找的字符串容器
:param xstr: 要查找的字符串
"""
xnum = 0
for i in range(zstr.count(f'{xstr}')):
xnum = zstr.find(f'{xstr}', xnum)
print(xnum, end=',')
xnum += len(xstr)
测试:
abc = '''This do cument rep orts on the results of an automatic security scan. All dates are dis-
played using the timezone "Co ordinated Universal Time", which is abbreviated "UTC". The
task was "every port". The scan started at Fri Oct 29 01:02:17 2021 UTC and ended at
Fri Oct 29 04:04:45 2021 UTC. The rep ort first summarises the results found. Then, for
each host, the rep ort describ es every issue found. Please consider the advice given in each
description, in order to rectify the issue.'''
strfindall(abc, 'i')
# 输出 2,52,60,85,98,107,122,131,140,148,152,161,223,265,306,317,379,391,415,427,432,437,450,453,458,474,482,
截图: