Q:

Write a Ruby program to check whether a string starts with "if"

0

 Write a Ruby program to check whether a string starts with "if" 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now