From: Gavin Sinclair Date: 2002-11-03T20:54:57+09:00 Subject: Re: substitution problem From: "SHULTZ,BARRY (HP-Israel,ex1)" > Hi, > > > > I'd like to capitalize every word in a string. > > > > > > 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? > > > > > > > how 'bout the block form? > > newstr = str.gsub(/\b(\s)?([a-z])/) { |s| s.upcase } > > that works for me. Or newstr = str.gsub(/\w+/) { |s| s.capitalize } > Regards, > Barry Gavin