Probably a dumb s/// question.

Discussion in 'Perl' started by Mark Healey, Mar 16, 2005.

  1. Mark Healey

    Mark Healey Guest

    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
     
    Mark Healey, Mar 16, 2005
    #1
    1. Advertising

  2. Mark Healey

    Paul Lalli Guest

    "Mark Healey" <> wrote in message
    news:p...
    > 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
     
    Paul Lalli, Mar 16, 2005
    #2
    1. Advertising

  3. At 2005-03-16 11:14AM, Mark Healey <> 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
     
    Glenn Jackman, Mar 16, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin
    Replies:
    2
    Views:
    265
    Justin
    Oct 9, 2006
  2. Tom Anderson

    Probably dumb JAR question

    Tom Anderson, Jan 25, 2009, in forum: Java
    Replies:
    6
    Views:
    410
    Roedy Green
    Jan 27, 2009
  3. Jerry C.
    Replies:
    8
    Views:
    256
    Uri Guttman
    Nov 23, 2003
  4. Mark Healey

    Probably a dumb s/// question.

    Mark Healey, Mar 16, 2005, in forum: Perl Misc
    Replies:
    13
    Views:
    214
    Joe Smith
    Mar 28, 2005
  5. Bob

    Probably a dumb question....

    Bob, Jan 23, 2007, in forum: Javascript
    Replies:
    2
    Views:
    78
Loading...

Share This Page