From: Nick Bo Date: 2008-09-19T09:35:48+09:00 Subject: Re: Array Count Issu Adam Shelly wrote: > On Thu, Sep 18, 2008 at 3:04 PM, Nick Bo 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 This was the simplest for me to understand since I am very new to using Ruby THANK YOU SOOO MUCH. Though it still needs tweaking it gives me alot of 1's for some reason? Ill show you EVERYTHING i got now. ./wordcount