Hi --

On Mon, 25 Jun 2007, Dan Stevens (IAmAI) wrote:

> name = "Mr John Joe Peter Smith"
> TITLES = ["Mr", "Mrs", "Ms", "Dr"]
> a = name.split
> last = a.pop
> title = a.shift if TITLES.include? a.first

Have mercy on us Yanks and allow for a period :-)

> first = a.shift
> middles = a
>
> title #=> "Mr"
> first #=> "John"
> middles #=> ["Joe", "Peter"]
> last #=> Smith"

However:

   name = "Mr Andrew Lloyd Webber"

   # etc.

   title #=> "Mr"
   first #=> "Andrew"
   middles #=> ["Lloyd"]   (wrong)
   last #=> Webber"        (wrong)


David

-- 
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)