Skip to content

Instantly share code, notes, and snippets.

@xiangzhuyuan
Created August 17, 2017 02:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiangzhuyuan/c63bc6dffa893da99f601ce82beb38bf to your computer and use it in GitHub Desktop.
Save xiangzhuyuan/c63bc6dffa893da99f601ce82beb38bf to your computer and use it in GitHub Desktop.
ruby string remove all whitespace

https://stackoverflow.com/questions/1634750/ruby-function-to-remove-all-white-spaces

String#strip - remove all whitespace from the start and the end.

String#lstrip - just from the start.

String#rstrip - just from the end.

String#chomp (with no arguments) - deletes line separators (\n or \r\n) from the end.

String#chop - deletes the last character.

String#delete - x.delete(" \t\r\n") - deletes all listed whitespace.

String#gsub - x.gsub(/[[:space:]]/, '') - removes all whitespace, including unicode ones.
@xiangzhuyuan
Copy link
Author

choose this:

String#gsub - x.gsub(/[[:space:]]/, '')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment