On Thu, Sep 18, 2008 at 3:04 PM, Nick Bo <bornemann1 / nku.edu> wrote:
> I dont want to know how many characters are in a word i want to find the
> word itself so how would i set it up so I could see how many instances
> of the word is in the string? would it be something like
>

irb> st = 'cat cat fox'
=> "cat cat fox"
irb> sa = st.split
=> ["cat", "cat", "fox"]

# since the string is now in the array, you can search the array
instead of the string.
irb> sa.grep(sa[0]).size
=> 2

#if you have to search through a string, here's a hack:
irb> ct=0;st.gsub(sa[0]){ct+=1};ct
=> 2


-Adam