Q:

Write a Ruby program to check whether a string 'Java' appears at index 1 in a given sting

0

 Write a Ruby program to check whether a string 'Java' appears at index 1 in a given sting, if 'Java' appears return the string without 'Java' otherwise return the string unchanged. 

All Answers

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

def text_test(str)
   if(str[1,4] == "Java")
		return (str[5, str.length()]);
	else
		return str;
	end
end
print text_test("ZJavaScript"),"\n"
print text_test("Oldjava")
 Output:
Script
Oldjava

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