Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Title Case 1

Status
Not open for further replies.

vasilek

Programmer
Jan 5, 2003
99
0
0
US
Hello. How to convert the text to a title case? Users usually type in all lower, all caps or mixed case.


Thanks you very much.
 
uc() #uppercase
--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
ucfirst #capitalize first char
lc #lowercase all chars
ucfirst(lc($var)) #title case
 
Or, an re solution:
$var =~ s/^(.)(.*)$/\U$1\L$2/;
 
mikevh,

ucfirst(lc($var))

doesn't seem to be working for the sentence.

Thanks.
 
ucfirst(lc($var)) will titlecase only the first word. Didn't know you wanted to do a whole sentence.
For a sentence, chazoid's solution works.
Or, combining the two:
$var =~ s/\b(.*?)\b/ucfirst(lc($1))/eg;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top