starting at the end of the string using negative numbers, get the second to last character through the eighth to last : char range « String « Ruby






starting at the end of the string using negative numbers, get the second to last character through the eighth to last


thoreau = "asdfasdfasdfadsfasdfasdfadsf"



puts thoreau[-8..-2]

 








Related examples in the same category

1.Retrieve part of a string with the [] method, using a range.
2.iterate over all the characters using a block
3.Range indexes are negative