w3resource

Ruby String Exercises: Remove a specified character into a given string

Ruby String: Exercise-12 with Solution

Write a Ruby program to remove a specified character into a given string.

Ruby String Exercises: Remove a specified character into a given string

Ruby Code:

def check_string(str,chr)
   return str.tr(chr, '')
end
print check_string("JavaScript", 'a')
print "\n",check_string("Python", 'y')
print "\n",check_string("PHP", 'H')

Output:

JvScript
Pthon
PP

Flowchart:

Flowchart: Remove a specified character into a given string

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to sort a string's characters alphabetically.
Next: Write a Ruby program to trim specific characters from a 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-12.php