Re: Search string for occurneces of words stored in array
- From: Ken Bloom <kbloom@xxxxxxxxx>
- Date: Wed, 30 Apr 2008 09:27:17 -0500
On Wed, 30 Apr 2008 09:01:11 -0500, 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
Ruby quiz #103: the DictionaryMatcher
http://www.rubyquiz.com/quiz103.html
You may need to do "This is my test sentence".split.any?{...} if it has
to specifically be on words. Note that
"I am running home".include? "run"
returns true, as does "abc def".include? "c d"
--Ken
--
Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
.
- References:
- Search string for occurneces of words stored in array
- From: John Butler
- Search string for occurneces of words stored in array
- Prev by Date: Re: Search string for occurneces of words stored in array
- Next by Date: Re: Search string for occurneces of words stored in array
- Previous by thread: Re: Search string for occurneces of words stored in array
- Next by thread: Re: Search string for occurneces of words stored in array
- Index(es):
Relevant Pages
|