From: Dave Baldwin Date: 2010-06-25T00:49:25+09:00 Subject: Re: Count substrings in string, scan too slow http://en.wikipedia.org/wiki/Boyer–Moore_string_search_algorithm If written in Ruby may not beat using the underlying library functions as they are written in C. I have vague recollections of a ruby quiz being based on something like this Dave. On 24 Jun 2010, at 16:04, Danny Challis wrote: > Hello everyone, > I need to count the number of times a substring occurs in a string. > I am currently doing this using the scan method, but it is simply too > slow. I feel there should be a faster way to do this since the scan > method is really designed for more advanced things than this. I do not > need to do regex matching or to process the matches, just count > substrings. So what I want is something like this: > > s = "you like to play with your yo-yo" > s.magical_count_method("yo") => 4 > > Once again, what I'm really looking for is something fast. I've tried > using external linux commands such as awk, but that was much much > slower. Any ideas? > Thanks, > > Danny. > -- > Posted via http://www.ruby-forum.com/. >