w3resource

Ruby String Exercises: Remove all white space within a string

Ruby String: Exercise-5 with Solution

Write a Ruby program to remove all white space within a string.

Ruby String Exercises: Remove all white space within a string

Ruby Code:

def check_string(my_string)
   return my_string.delete(' ')
end
print check_string("Ja v aS cr     ip      t")

Output:

JavaScript

Flowchart:

Flowchart: Remove all white space within a string

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to check whether a string contains a substring.
Next: Write a Ruby program to remove last specified characters from a given string.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/ruby-exercises/string/ruby-string-exercise-5.php