Normalize Whitespace

Replace multiple consecutive whitespace characters with a single space and trim edges.

Code

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

Parameters

String with irregular whitespace

Server

More Ruby Snippets