From: Justin Collins Date: 2006-04-29T06:08:45+09:00 Subject: Re: Counting words Bira wrote: > On 4/28/06, Bira wrote: >> number_of_words = string.split(/\s/).length > > Eh, sorry. I meant to write: > > number_of_words = string.split(/\s+/).length > > The "+" is needed to cover words with more than one whitespace > character between them. > > -- > Bira > http://compexplicita.blogspot.com > http://sinfoniaferida.blogspot.com > Just plain string.split.length will work as well, and should handle line breaks too: > irb(main):001:0> "these are some words".split.length > => 4 > irb(main):002:0> "these are \n some\nwords".split.length > => 4 > irb(main):003:0> "these are \n some\nwords".split > => ["these", "are", "some", "words"] > irb(main):004:0> Hope that helps. -Justin