On Oct 7, 2005, at 2:31 PM, rpardee / gmail.com wrote: > Hey All, > > I've got to suck some address info out of a db, where it is stored in > all caps, like so: > > 14 WEST 21ST ST > 742 NW EVERGREEN TERRACE > PO BOX 13 > > And I want to pretty up the casing: > > 14 West 21st St > 742 NW Evergreen Terrace > PO Box 13 > > So it's mostly just title-casing, and then dealing w/certain special > components like 'NE', 'SW', 'PO' and so forth. > > I've actually got some vb.net code that I could convert, but I thought > I'd ask here whether someone's already got something they've sweated > over before I did. > > Also--more concretely: for simple title-casing, is this the > easiest/best approach? > > pretty_address = my_address_var.split.each do |c| c.capitalize > end.join(" ") > > Or is there something more graceful/efficient? My thought is something like this: abbreviations = %w{NW SW PO} # ... etc ... my_address.gsub!(/[A-Z]+/) { |w| abbreviations.include?(w) ? w : w.capitalize } Hope that helps. James Edward Gray II