From: James Edward Gray II Date: 2005-10-08T08:03:48+09:00 Subject: Re: Code for title-casing (US) snail addresses? On Oct 7, 2005, at 5:46 PM, rpardee@gmail.com wrote: > And thanks again! Glad to help. > If I can beg your indulgence a bit further... I'm having trouble > elaborating this so it does the right thing for street names like > 'McGrath'. The simpler version is: See if this works (untested): > def prettify(address) > abbreviations = %w(PO NE NW SE SW) > prefixes2 = %w(Mc O' D') > prefixes3 = %w(Mac) > address.gsub!(/(\d)([A-Z]+)/) { $1 + $2.downcase } > address.gsub(/[A-Z]+/) do |w| > # abbreviations.include?(w) ? w : w.capitalize > if abbreviations.include?(w) then > w > else > w.capitalize > end > end address.gsub!(/\b(#{prefixes2.join("|")})(\w)/) { $1 + $2.capitalize } > end James Edward Gray II