From: "Hal E. Fulton" Date: 2002-11-03T16:53:30+09:00 Subject: Re: substitution problem ----- Original Message ----- From: "Daniel Bretoi" To: "ruby-talk ML" Sent: Sunday, November 03, 2002 1:18 AM Subject: substitution problem > Hi All, > > I'd like to capitalize every word in a string. One way: str.split.map {|x| x.capitalize}.join(" ") but you may not be happy with the way it treats spaces and such. > I was hoping this expression would do it: > > newstr = str.gsub(/\b(\s)?([a-z])/,'\1\2'.upcase) > > but it turns out that as \2 is not evaluated right away, the .upcase has > no effect. Suggestions? Maybe break it up. str = "what hath god wrought?" newstr = "" str.scan(/(\w)(\w+)(\W)*/) {|x,y,z| newstr << x.upcase << y << z} p newstr # "What Hath God Wrought?" This works for me. Depends on your data. Hal