Ruby - String OperationsWhich of these is the correct syntax to get the substring 'gram' from str = "programming"?Astr[3, 4]Bstr[3..5]Cstr[4..7]Dstr[4, 3]Check Answer
Step-by-Step SolutionSolution:Step 1: Identify substring 'gram' position'gram' starts at index 3: p(0)r(1)o(2)g(3)r(4)a(5)m(6)...Step 2: Use start index and length syntaxstr[3, 4] extracts 4 characters starting at index 3, which is 'gram'.Final Answer:str[3, 4] -> Option AQuick Check:Start index + length slicing = correct substring [OK]Quick Trick: Use str[start, length] for substring extraction [OK]Common Mistakes:Using range with wrong end indexConfusing length with end indexOff-by-one errors in slicing
Master "String Operations" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Compact for removing nil values - Quiz 2easy Arrays - Array methods (length, include?, flatten) - Quiz 9hard Hashes - Default values for missing keys - Quiz 4medium Hashes - Default values for missing keys - Quiz 12easy Hashes - Hash creation with symbols and strings - Quiz 3easy Loops and Iteration - Loop method for infinite loops - Quiz 6medium Loops and Iteration - Upto and downto methods - Quiz 4medium Operators and Expressions - Why operators are methods in Ruby - Quiz 7medium String Operations - String freezing for immutability - Quiz 13medium Variables and Data Types - String interpolation with #{} - Quiz 3easy