Ruby Basic Exercises: Check whether a string starts with 'if'
Ruby Basic: Exercise-5 with Solution
Write a Ruby program to check whether a string starts with "if".
Ruby Code:
def start_if(str)
return str[0, 2] == "if";
end
print start_if("ifelse"),"\n"
print start_if("endif"),"\n"
Output:
true false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program which accept the radius of a circle from the user and compute the parameter and area.
Next: Write a Ruby program which accept the user's first and last name and print them in reverse order with a space between them.
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