From: Phillip Gawlowski Date: 2008-04-30T23:09:01+09:00 Subject: Re: Search string for occurneces of words stored in array -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Butler wrote: | Hi, | | I have a sentence "This is my test sentence" and an array["is", "the", | "my"] and what i need to do is find the occurence of any of thearray | words in the sentence. | | I have this working in a loop but i was wondering is there a way to do | it using one of rubys string methods. | | Its sililar to the include method but searching for multiple words not | just one. | | "This is my test sentence".include?("This") returns true | | but i want something like | | "This is my test sentence".include?("This", "is", "my") | | anyone got a nice way to do this? I only need to find if one of the | words occure and then i exit. | | JB How about '["is", "the", "my"].each'? I.e.: ["is", "the", "my"].each do |word| ~ break if "the test sentence'.include? word end - -- Phillip Gawlowski Twitter: twitter.com/cynicalryan Blog: http://justarubyist.blogspot.com ~ - You know you've been hacking too long when... ...you dream that your SO and yourself are icons in a GUI and you can't get close to each other because the window manager demands minimum space between icons... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgYfXsACgkQbtAgaoJTgL8swgCfW6ixKWKPo2HT8CQzGFeDcaNu w6sAnRTk5hihGfh0hZMRBiCiOHEceZpA =JpPT -----END PGP SIGNATURE-----