On Thu, May 28, 2009 at 9:34 PM, Li Chen <chen_li3 / yahoo.com> wrote:
> How to find out pattern'cat'  ¨Βτθισ στςιξη½§γγγγατηηηγταγατηηητγατ> ? There are three 'cat' within the string and I want to  ¨Βετυς ¨Βθε ποσιτιοξ οζ εαγθ νατγθ®

there is String#index.
there is no indexes, but you can build one if you like

eg,

> s
=> "ccccatgggctacatgggtcat"
> class String
> def indexes str, n=0
>  n=index( str, n)
>   if n
>     [n] + indexes( str, n+=1)
>   else
>     []
>   end
> end
> end
=> nil
> s.indexes "cat"
=> [3, 12, 19]

the faster way is to loop, but i just want to test my recursion skill  ;)

best regards
-botp