Ruby 1.9 introduces +String#bytesize+ to obtain the length of a string in bytes. Ruby 1.8.7 defines this method as an alias for +String#size+ for forward compatibility, and Active Support does so for previous versions.
+The method +String#squish+ strips leading and trailing whitespace, and substitutes runs of whitespace with a single space each:
+" \n foo\n\r \t bar \n".squish # => "foo bar"
+There's also the destructive version +String#squish!+.