capitalizing first letter in each line of a string.

R

Richard Powell

Hi, =0AIm in need of capitalizing first letter of each line in a long strin=
g, and have =0Ait print exactly the same (but with the first word capitaliz=
ed+with the =0Awhitespace).. but cant figure it out.. any advise?=0A=0Ataco=
=A0=3D <<-HERE=0A=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0to bad I hate tacos they=A0taste great..=0A=A0 so much for a HEALTHY die=
t....=0A=0AHERE=0A=0Ataco.scan(/\W+\.*\w+\.*/){|x| print x.capitalize}=0A=
=0A______=0A=0Aim guessing my regular expression is wrong. and possibly the=
.capitalize is in =0Athe wrong space?=0Asorry im a newbie :)=0Athanks=0Ari=
ch=0A=0A=0A =0A____________________________________________________________=
________________________=0ADon't pick lemons.=0ASee all the new 2007 cars a=
t Yahoo! Autos.=0Ahttp://autos.yahoo.com/new_cars.html
 
P

Peter Zotov

Hi,=20
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?
=20
taco=C2=A0=3D <<-HERE
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0to bad I hate tacos they=C2=
=A0taste great..
=C2=A0 so much for a HEALTHY diet....
=20
HERE
=20
taco.scan(/\W+\.*\w+\.*/){|x| print x.capitalize}
=20
______
=20
im guessing my regular expression is wrong. and possibly
the .capitalize is in the wrong space?
sorry im a newbie :)
thanks
rich

Here you are:

taco =3D <<-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 }

--=20
WBR, Peter Zotov
 
R

Richard Powell

[Note: parts of this message were removed to make it a legal post.]

thanks!



________________________________
From: Peter Zotov <[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.

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 they taste 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 :)
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 }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top