From: Ross Bamford Date: 2006-12-21T18:05:05+09:00 Subject: Re: Searching Stings with Arrays? On Wed, 20 Dec 2006 22:06:49 -0000, Phil Cooperking wrote: > Hi, I've been having a little problem with this. most of my ruby is from > rails and both are shaky. > > okay what I've got is a string (which is a browser user agent) and I > would like to search that string with a predefined array of browsers. > I've done this in php so I'm positve an easy solution exists in Ruby > > this is what I got > @string = "mozilla/5.0 (macintosh; u; ppc mac os x; en) > applewebkit/418.9.1 (khtml, like gecko) safari/419.3" > > array = ["shiira", "msie", "safari", "firefox", "netscape"] > > so I'd like to search the string for any matches, it should stop at > safari and bob's sombodys uncle. > > this is what I've been trying to do. > array.find {|b| b == @string}.to_s > > this does't work I know, but I'm I in the right direction? > You already have your answers it seems, so for completeness I'll just mention a recent ruby quiz: http://rubyquiz.com/quiz103.html It focused on larger word sets that you're looking at, but it might give you a different perspective on the problem. -- Ross Bamford - rosco@roscopeco.remove.co.uk