Swati
Swati

Reputation: 862

Determine which substring from array is present in given string

I have a array of few string

For ex: ["hello", "World", "nice"]

Now i have a long url string with special string.

I want to find out which string from above array is present in my url string using Ruby and return that string.

Upvotes: 0

Views: 51

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37419

Use find:

words.find { |w| url[w] }

Example:

 ["hello", "World", "nice"].find { |w| "this is nice"[w] }
 # => "nice"

Upvotes: 2

Related Questions