The strip
method in Ruby creates a copy of the original string with the leading and trailing whitespace removed. The following characters constitute whitespace elements:
Character | Symbol |
---|---|
null | \x00 |
horizontal tab | \t |
vertical tab | \v |
new line | \n |
form feed | \f |
carriage return | \r |
space | " " |
The illustration below shows how strip
works in Ruby:
The strip
method returns a copy of the original string with trailing and leading whitespace removed.
The code snippet below shows how we can use strip
in Ruby:
puts "\vstring\t\n ".stripputs " string ".strip
Free Resources