RubyGuides
Share this post!

Squashing spaces

If we want to remove extra spaces in a text like this:

You could be tempted to use sed, but there is a simpler way using tr

And we end up with:

With tr you canĀ also delete characters instead of compressing them. Let’s say we wanted to get rid of the vowels.

We get: