String Occurance Counting Algorithm

Posted by Hellnar on Stack Overflow See other posts from Stack Overflow or by Hellnar
Published on 2010-05-04T18:42:37Z Indexed on 2010/05/04 19:08 UTC
Read the original article Hit count: 198

Filed under:
|
|

Hello, I am curious what is the most efficient algorithm (or commonly used) to count the number of occurances of a string in a chunck of text.

From what I read, Boyer–Moore string search algorithm is the standard for string search but I am not sure if counting occurance in an efficient way would be same as searching a string.

In python this is what I want:

text_chunck = "one two three four one five six one"
occurance_count(text_chunck, "one") # gives 3.

Regards

EDIT: It seems like python str.count serves me such method however I am not able to find what algorithm it uses.

© Stack Overflow or respective owner

Related posts about string

Related posts about search