What is the Ruby function to remove all white spaces? I'm looking for something kind of like PHP's trim()
?
The lstrip() method will remove leading whitespaces, newline and tab characters on a string beginning.
Method 1: Using ltrim() Method: The ltrim() method is used to strip whitespace only from the beginning of a string.
The . strip method removes the leading and trailing whitespace on strings, including tabs, newlines, and carriage returns ( \t , \n , \r ).
If you want to remove only leading and trailing whitespace (like PHP's trim) you can use .strip
, but if you want to remove all whitespace, you can use .gsub(/\s+/, "")
instead .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With