Probably a dumb s/// question.

M

Mark Healey

I'm trying to craft a search that capitalizes letters depending on their
context, specifically after a space or the beginning of a string.

For example I'd like to turn

the quick brown fox jumped over the lazy dogs.

to

The Quick Brown Fox Jumped Over the Lazy Dogs.

Is this doable on a single line?
 
P

Paul Lalli

Mark Healey said:
I'm trying to craft a search that capitalizes letters depending on their
context, specifically after a space or the beginning of a string.

For example I'd like to turn

the quick brown fox jumped over the lazy dogs.

to

The Quick Brown Fox Jumped Over the Lazy Dogs.

Is this doable on a single line?

What have you tried so far?

Have you read the posting guidelines for this group, posted twice a
week?

Because I'm feeling generous (and bored) anyway:

s/(^|\s)([a-z])/$1\u$2/g;


for more information on ^, |, (), $1 & $2:
perldoc perlre
perldoc perlretut
perldoc perlreref

for more information on \u:
perldoc -f ucfirst

Paul Lalli
 
G

Glenn Jackman

At 2005-03-16 11:14AM said:
For example I'd like to turn
the quick brown fox jumped over the lazy dogs.
to
The Quick Brown Fox Jumped Over the Lazy Dogs.

Is this doable on a single line?

my $string = 'the quick brown fox jumped over the lazy dogs.';
my $String = join ' ', map {ucfirst lc} split ' ', $string;

That forces your string to lower case first then capitalizes the first
letter. It won't preserve whitespace though.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top