Ruby String Exercises: Remove the first and last two characters from a specified string
Ruby String: Exercise-14 with Solution
Write a Ruby program to remove the first and last two characters from a specified string.
Ruby Code:
def check_string(str)
str = str[2...-2]
return str
end
print check_string("JavaScript")
print "\n",check_string("Python")
print "\n",check_string("Ruby")
print "\n",check_string("PHP")
Output:
vaScri th
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to trim specific characters from a string.
Next: Write a Ruby program to get a substring from a specified position to the last char of a given string.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework