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
Ways to skip test case execution in Gradle project build Learn Gradle | tutorials, and examples How to run only single test cases with Gradle build How to print dependency tree graph in Gradle projects How to perform git tasks with build script?Related posts