From: Craig Kim Date: 2006-04-08T22:33:53+09:00 Subject: Re: Ruby string On Sat, 8 Apr 2006, dblack@wobblini.net wrote: > On Sat, 8 Apr 2006, Peter wrote: > >> string = "this is a String" >> string.capitalize = "This is a string" >> That works but changes my capital "a String" to lowercase. >> >> I only want to capitalize first letter. >> So I try" >> string[0..0].capitalize >> irb => "T" >> OK >> string[0..0].capitalize! >> irb => "T" >> irb string >> irb => "this is a string" >> > What you've done is to create a new string, consisting of the single > character 't'. Then you've done an in-place capitalize on that > string; then you've discarded it :-) > Another not-so-brilliant way to do is to put the created string back to the original string by doing this: string[0..0] = string[0..0].upcase > I can't think of a better way to do this than what's already been > posted, though it really does feel like there should be. I agree.