The index method returns the index location of a matching substring. : index « String « Ruby






The index method returns the index location of a matching substring.


So if you use index like this:

line = "A horse! a horse! my kingdom for a horse!"
puts line.index("k")

 








Related examples in the same category

1.line[line.index("k")]
2.Index and last index a pattern
3.Replace first vowel with an asterisk