Search⌘ K

Word Count

Explore how to count the number of words in a string with Ruby by splitting the text into tokens separated by whitespace. This lesson helps you understand string tokenization and the use of Ruby methods like split and size to accurately count words, even when multiple spaces exist.

We'll cover the following...

Problem

Let's say a person, Emily, wrote a book review, but she is not sure whether it meets the required word count. Assuming Emily’s article is already saved in an input string, write a program ...