Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Probably a dumb s/// question.

Reply
Thread Tools

Probably a dumb s/// question.

 
 
Mark Healey
Guest
Posts: n/a
 
      03-16-2005
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?


--
Mark Healey
marknews(at)healeyonline(dot)com

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      03-16-2005
"Mark Healey" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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

 
Reply With Quote
 
 
 
 
Glenn Jackman
Guest
Posts: n/a
 
      03-16-2005
At 2005-03-16 11:14AM, Mark Healey <(E-Mail Removed)> wrote:
> 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.

--
Glenn Jackman
NCF Sysadmin
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
probably a dumb question, but I cant figure it out.... Justin Java 2 10-09-2006 12:40 AM
Probably a dumb question but.... Bob Computer Information 3 08-14-2006 10:35 PM
Probably A really Dumb Enveloping Printing Question Rose Bush Computer Support 7 03-31-2005 09:38 PM
A Really Dumb (Probably) OE Question Pop Aye Computer Support 4 11-06-2004 05:27 AM
Dumb, dumb dumb Qestion David Napierkowski Digital Photography 6 10-31-2004 11:14 PM



Advertisments