DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Ruby: Count Number Of Words In A String
class String
def count_words
n = 0
scan(/\b\S+\b/) { n += 1}
n
end
end





Comments
replied on Thu, 2007/04/12 - 4:41pm