From: Brian Schroeder Date: 2004-09-26T03:24:27+09:00 Subject: Re: Formatting addresses question On Sat, 25 Sep 2004 10:36:13 -0700, Daniel Kelley wrote: > Matthew Margolis writes: > >> I currently have a large text file based address book(for myself, not >> spamming) that I am working on making suitable for import into a >> database. To do this I need comma separated values. How would I go >> about adding a comma after the state in the person's mailing address? >> >> An example record: >> >> Name: Bob Fakeyhead >> Title: Old Boss >> Phone: 555-555-5555 >> Mailing: 23456 Something Street >> OldPlace, WA 55555 >> >> > > If you are using Ruby 1.8, you can use the CSV module. > > http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/ > > [...] > require 'csv' > If I understand him correctly, this solves creating correct csv output, but he has to parse the input. A regexp to split the adress line would be >> OldPlace, WA 55555 raise "Unknown address format" unless /(.*?),\s*(\w*)\s*(\d*)/ =~ address_line address[:town] = $1; address[state] = $2, address[:code] => $3} regards, Brian -- Brian Schræ—¦der http://www.brian-schroeder.de/