From: Bira Date: 2006-04-29T02:48:17+09:00 Subject: Re: Counting words On 4/28/06, Jamal Mazrui wrote: > I've research this but am still having trouble getting it right .... > Can someone give me code that counts the number of words in a string via > RegExp and MatchData objects? I think I'd like a word to be defined as > contiguous characters surrounded by white space (or the start/end of the > string), though am open to other interpretations. > > Jamal > I'm a bit of a nuby, and this is my first post to the list, but I think the following one-liner will do the job: number_of_words = string.split(/\s/).length I haven't tested it because I'm at work without access to a Ruby interpreter :(. -- Bira http://compexplicita.blogspot.com http://sinfoniaferida.blogspot.com