Ruby String Exercises: Trim specific characters from a string
Ruby String: Exercise-13 with Solution
Write a Ruby program to trim specific characters from a 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("JavaScript", 'JS')
Output:
JvScript Pthon avacript
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to remove a specified character into a given string.
Next: Write a Ruby program to remove the first and last two characters from a specified string.
What is the difficulty level of this exercise?
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://www.w3resource.com/ruby-exercises/string/ruby-string-exercise-13.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics