Trim Extra Whitespace

Remove extra whitespace from a string, keeping single spaces between words.

Code

General
str.strip.gsub(/\s+/, ' ')

Parameters

The string to clean up

Server

More Ruby Snippets