Capitalizing first letter in each line of a string

Hi,
Im in need of capitalizing first letter of each line in a long string,
and have
it print exactly the same (but with the first word capitalized+with the
whitespace)… but cant figure it out… any advise?

taco= <<-HERE
to bad I hate tacos theytaste great…
so much for a HEALTHY diet…

HERE

taco.scan(/\W+.\w+./){|x| print x.capitalize}


im guessing my regular expression is wrong. and possibly the .capitalize
is in
the wrong space?
sorry im a newbie :slight_smile:
thanks
rich

On Thu, 10 Feb 2011 05:32:50 +0900
Richard P. [email protected] wrote:

HERE

taco.scan(/\W+.\w+./){|x| print x.capitalize}


im guessing my regular expression is wrong. and possibly
the .capitalize is in the wrong space?
sorry im a newbie :slight_smile:
thanks
rich

Here you are:

taco = <<-HERE
to bad I hate tacos they taste great…
so much for a HEALTHY diet…

HERE

p taco.gsub(/^(\W*?[a-z])/) { |m| m.upcase }

thanks!


From: Peter Z. [email protected]
To: ruby-talk ML [email protected]
Sent: Wed, February 9, 2011 12:44:50 PM
Subject: Re: capitalizing first letter in each line of a string.

On Thu, 10 Feb 2011 05:32:50 +0900
Richard P. [email protected] wrote:

HERE

taco.scan(/\W+.\w+./){|x| print x.capitalize}


im guessing my regular expression is wrong. and possibly
the .capitalize is in the wrong space?
sorry im a newbie :slight_smile:
thanks
rich

Here you are:

taco = <<-HERE
to bad I hate tacos they taste great…
so much for a HEALTHY diet…

HERE

p taco.gsub(/^(\W*?[a-z])/) { |m| m.upcase }

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs