Free2Code
 
Time: 2008-12-04, 09:24pm
making names capital/lowercase
Subject: making names capital/lowercase  ·  Posted: 2004-09-27, 09:28am
Rank: ? (171)
Member #: 11947
I have an all uppercase name ( LASTNAME, FIRSTNAME), and would like to convert the first letter of each name to uppercase, while the rest is lower. Is there an easy why to do this without parsing the string into four parts?

thanks

 
  Reply to this ·  Post link ·  Top
Subject: Re: making names capital/lowercase  ·  Posted: 2004-10-04, 07:12am
Rank: ? (171)
Member #: 11947
I'm saddened that nobody realized this....

s/(.)([^,]*), (.)(.*)/ \1lc(\2), \3lc(\4)/gi

this right?

» Post edited 2004-11-15, 04:11am by Umojan.

 
  Reply to this ·  Post link ·  Top
Subject: Re: making names capital/lowercase  ·  Posted: 2004-12-04, 10:45am
Rank: Unregistered
You should be able to do this:

$strFirstName = "\L\u$strFirstName\E";
$strLastName = "\L\u$strLastName\E";

The "\L" makes everything lowercase. The "\u" makes the first letter uppercase.
Just as "\U" would make everything uppercase and "\l" would make the first letter lowercase.

You need to use "\E" with "\L" or "\U" which signifies where to end making text upper or lowercase.
 
  Reply to this ·  Post link ·  Top
Subject: Re: making names capital/lowercase  ·  Posted: 2005-02-07, 07:42pm
Rank: Unregistered
Or to do the first letter of each word:

$fullName = lc($fullName);
$fullName =~ s/(\b|,)([a-z])/$1\U$2\E/g;

The "(\b|,)" is just incase there's no space after the comma.

e.g. "JOHN, SMITH" would become "John, Smith"

Hope this helps.
 
  Reply to this ·  Post link ·  Top
Subject: Re: making names capital/lowercase  ·  Posted: 2005-05-17, 08:41am
Rank: ? (1)
Member #: 24100
Or, this:

$fullName = ucfirst($fullName);

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons