index

str.index(substring [, offset]) â fixnum or nil
str.index(regexp [, offset]) â fixnum or nil
Instance Public methods

Returns the index of the first occurrence of the given substring or pattern (regexp) in str. Returns nil if not found. If the second parameter is present, it specifies the position in the string to begin the search.

"hello".index('e')             #=> 1
"hello".index('lo')            #=> 3
"hello".index('a')             #=> nil
"hello".index(?e)              #=> 1
"hello".index(/[aeiou]/, -3)   #=> 4
doc_ruby_on_rails
2015-05-15 17:02:29
Comments
Leave a Comment

Please login to continue.