THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This tutorial explains how to remove whitespaces from a given string in Ruby.
String strip method
removes the whitespaces from the start and end of a string.
result=" welcome to my website ".strip
puts "-#{result}-"
Output:
-welcome to my website-
String lstrip method
removes the whitespaces from starting a string.
result=" welcome to my website ".lstrip
puts "#{result}"
-welcome to my website -
String rstrip method
removes the whitespaces from the end of a string.
result=" welcome to my website ".lstrip
puts "#{result}"
- welcome to my website-
delete method
in a string removes all given parameters from a string and returns result string.
Here is an example
result=" welcome to my website ".delete(" ")
puts "#{result}"
Output:
welcometomywebsite
🧮 Tags
Recent posts
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?Related posts