[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Search a word in a string

Lloyd Linklater

11/6/2008 2:34:00 PM

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-....