String Occurrence Counting Algorithm
问题 I am curious what is the most efficient algorithm (or commonly used) to count the number of occurrences of a string in a chunk of text. From what I read, the Boyer–Moore string search algorithm is the standard for string searches but I am not sure if counting occurrences 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. EDIT: It seems like python str.count