This is a discussion on Re: Search a word in a string - RUBY ; Ganesh Ganesh wrote: > Is there any ruby supported methods is there for searching a word in a > particular string > > For Example "Hi this is for test" > i need to search "Hi" Wouss is correct that ...
Ganesh Ganesh wrote:
> Is there any ruby supported methods is there for searching a word in a
> particular string
>
> For Example "Hi this is for test"
> i need to search "Hi"
Wouss is correct that a simple search would have shown you the answer.
Still, I ask questions here and it is my turn to help with an answer.
With something like this:
"Hi this is for test".index('Hi')
you get a nil if there is no match and the starting point of the string
found if there is one.
e.g.
puts 'string found' unless "Hi this is for test".index('Hi') == nil
--
Posted via http://www.ruby-forum.com/.