making names capital/lowercase
|
|||
|
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 |
||
|
|||
|
|||
|
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.
|
||
|
|||
|
|||
|
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. |
||
|
|||
|
|||
|
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. |
||
|
|||
|
|||
|
Rank: ? (1)
Member #: 24100 |
Or, this:
$fullName = ucfirst($fullName); |
||
|
Please login or register to post a reply.