To find the first index of a substring in a string in Ruby, you can use the index
method of the string class. Here's an example:
main.rb104 chars5 lines
In the code above, we create a string called my_string
and a substring called substring
. We then use the index
method to find the first index of the substring in the string and assign it to a variable called index
. Finally, we print the value of the index
variable, which should output 6
.
gistlibby LogSnag