mike.s.mckinney
12/14/2007 7:12:00 PM
[Note: parts of this message were removed to make it a legal post.]
just pass in the delimeter...
test.rb:
and_str = "foo and bar AND baz"
pipe_str = "foo|bar| baz"
def translate(str, del)
str.split(/\s*#{del}\s*/i).map{|s| "+#{s}"}.join(' ')
end
puts translate(and_str, 'and')
puts translate(pipe_str, '\|')
On Dec 14, 2007 1:50 PM, Phrogz <phrogz@mac.com> wrote:
> On Dec 14, 11:22 am, MenTaLguY <men...@rydia.net> wrote:
> > On Sat, 15 Dec 2007 03:19:22 +0900, Rolando Abarca <funkas...@gmail.com>
> wrote:
> > >> Can anyone help with an elegant solution?
> >
> > > "foo and bar and baz".split(/\s+and\s+/i).map{|s| "+#{s}"}.join(' ')
> >
> > I think this one is best.
>
> It's elegant, but it assumes that the search phrase always has "and".
> Although not originally specified either way, that seems like an
> unlikely assumption. But then, I don't know the problem domain.
>
>