index(substring [, offset]) → fixnum or nil index(regexp [, offset]) → fixnum or nil
Returns the index of the first occurrence of a given substring or pattern (regexp) in str. Returns nil if not found. If a second parameter is present, it indicates the position in the string to start the search.
"hello".index('e') #=> 1 "hello".index('lo') #=> 3 "hello".index('a') #=> nil "hello".index(?e) #=> 1 "hello".index(/[aeiou]/, -3) #=> 4
Check out ruby documents for more information.
kingasmk May 19 '12 at 20:02 2012-05-19 20:02
source share