If you want to erase the blank character at the front/back, like PHP's trim, you can use strip
irb(main):001:0> mystr = " hello "
=> " hello "
irb(main):002:0> puts mystr
hello
=> nil
irb(main):003:0> puts mystr.strip
hello
=> nil
irb(main):004:0>
Use .gsub(/\s+/, "")
to remove blank characters from the entire string
irb(main):001:0> mystr = " hello Ruby "
=> " hello Ruby "
irb(main):002:0> puts mystr.strip
hello Ruby
=> nil
irb(main):003:0> puts mystr.gsub(/\s+/, "")
helloRuby
=> nil
irb(main):004:0>
© 2024 OneMinuteCode. All rights reserved.