David A. Black wrote:
> Hi --
> 
> On Sat, 7 Nov 2009, Marnen Laibow-Koser wrote:
> 
>>> "city name ST 12345-6789" to City, State, and Zip Code fields.  I look
>>> for the first blank from the end of the string and assume everything
>>> after it is the Zip Code, I then find the next two non-blank characters
>>> and assign them to State, and everything else is the City name.
>>
>> That's great in a language like C that doesn't have very good string
>> handling.  The Ruby way to do this would be
>> city, state, zip = string.split(/\s+/)
> 
> You'd need to take multi-word city names into account, though. So
> maybe:
> 
>    city, state, zip = /\A(.*)\s+(\S+)\s+(\S+)\Z/.match(str).captures
> 

Quite right.  I was trying for simplicity, but that had indeed crossed 
my mind.

> 
> David
> 
> --
> The          Ruby training with D. Black, G. Brown, J.McAnally
> Compleat     Jan 22-23, 2010, Tampa, FL
> Rubyist      http://www.thecompleatrubyist.com
> 
> David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen / marnen.org
-- 
Posted via http://www.ruby-forum.com/.