From: Massimiliano Mirra Date: 2002-11-04T23:46:29+09:00 Subject: Re: substitution problem On Sun, Nov 03, 2002 at 04:53:30PM +0900, Hal E. Fulton wrote: > > 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. Similar to your second example and preserving spaces: str = "the quick brown fox, jumped over the lazy dog" str.scan(/(\w+)(\W+)*/).flatten.map {|x| x.capitalize unless x.nil?}.join > This works for me. Depends on your data. Ditto. :-) Massimiliano