Ruby String: Exercises, Practice, Solution
Ruby String Exercises[18 exercises with solution]
1. Write a Ruby program to draw a string as bold or italic text. Go to the editor
Sample Output:
<i> Ruby </i> <b> Ruby </b>
2. Write a Ruby program to insert a string of length 2 to an another string where the first string will be in the middle of the second string. Go to the editor
Sample Output:
Python Pythonz Pyothnxz
3. Write a Ruby program to lower case, upper case and capitalizes all the words of a given string. Go to the editor
Sample Output:
RUBY EXERCISES! ruby exercises! Ruby exercises!
4. Write a Ruby program to check whether first and the last element are the same of an given array of integers. The array length must be 1 or more. Go to the editor
Sample Output:
Substring present in the string. Substring not present in the string.
5. Write a Ruby program to remove all white space within a string. Go to the editor
Sample Output:
JavaScript
6. Write a Ruby program to remove last specified characters from a given string. Go to the editor
Sample Output:
JavaScrip JavaScri JavaScr JavaSc JavaS
7. Write a Ruby program to split a delimited string and convert it to an array. Go to the editor
Sample Output:
["A", "B", "C", "D", "E", "F"] ["A", "B", "C", "D", "E", "F"]
8. Write a Ruby program to remove a substring from a specified string. Go to the editor
Sample Output:
Java CSS
9. Write a Ruby program to check whether a string starts with an other string. Go to the editor
Sample Output:
true false
10. Write a Ruby program to count the occurrences of a specified character in a given string. Go to the editor
Sample Output:
1 2 1
11. Write a Ruby program to sort a string's characters alphabetically. Go to the editor
Sample Output:
aacijprstv hnopty HPP
12. Write a Ruby program to create a new array with the elements in reverse order from a given an array of integers length 3. Go to the editor
Sample Output:
JvScript Pthon PP
13. Write a Ruby program to trim specific characters from a string. Go to the editor
Sample Output:
JvScript Pthon avacript
14. Write a Ruby program to remove the first and last two characters from a specified string. Go to the editor
Sample Output:
vaScri th
15. Write a Ruby program to get a substring from a specified position to the last char of a given string. Go to the editor
Sample Output:
crip ho b PH
16. Write a Ruby program to get the number of lines in a given string. Go to the editor
Sample Output:
Number of lines of the above string: 6
17. Write a Ruby program to truncate a given string to the first n words. Go to the editor
Sample Output:
Python is a Python is a widely used high-level, general-purpose, interpreted, Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
18. Write a Ruby program to remove a character from a given string if it starts with that specified character. Go to the editor
Sample Output:
JavaScript PHP
Ruby Code Editor:
- 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