(mainString,pattern)
| 8 | m=length of pattern string |
| 9 | """ |
| 10 | def naivePatternSearch(mainString,pattern): |
| 11 | patLen=len(pattern) |
| 12 | strLen=len(mainString) |
| 13 | position=[] |
| 14 | for i in range(strLen-patLen+1): |
| 15 | match_found=True |
| 16 | for j in range(patLen): |
| 17 | if mainString[i+j]!=pattern[j]: |
| 18 | match_found=False |
| 19 | break |
| 20 | if match_found: |
| 21 | position.append(i) |
| 22 | return position |
| 23 | |
| 24 | mainString="ABAAABCDBBABCDDEBCABC" |
| 25 | pattern="ABC" |