Hi --

On 4/19/07, Yusuf Celik <ycelik / oytek.com.tr> wrote:
> Sorry made a mistake
> line=gets.chomp
> cnt = 0
> line.split.each {
>   |v|
>   if v == 'Hi' then
>      cnt +=1
>   end
> }
> puts "#{cnt}"

You could do:

line.scan(/\bHi\b/).size

(or \s instead of \b if you want it to be spaces instead of word
boundaries [which can also be hyphens and other punctuation]).


David

-- 
Upcoming Rails training by Ruby Power and Light:
  Four-day Intro to Intermediate
  May 8-11, 2007
  Edison, NJ
  http://www.rubypal.com/events/05082007