Ruby String Exercises: Remove a character from a given string if it starts with that specified character
Write a Ruby program to remove a character from a given string if it starts with that specified character.
Ruby Code:
my_string = "JJavaScript"
print my_string.sub!(/^J/, '')
my_string = "PPHP"
print "\n",my_string.sub!(/^P/, '')
Output:
JavaScript PHP
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to truncate a given string to the first n words.
Next: Ruby Exercise
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics