Dave's Brain

Browse - programming tips - perl title case

Date: 2008jan14
Language: perl

Q.  How do I convert a string to title case with Perl?

A.  Title Case Is Where Each Word Begins With An Uppercase Letter.
    Use this replacement:

	$title =~ s/(\w+)/\u\L$1/g;

    For each word (\w+) use the \u\L command.
    This is exactly the kind of thing that Perl was made for!

    Some related functions:

	$title = uc($title);	# To UPPERCASE
	$title = lc($title);	# To lowercase
	$title = ucfirst($title) # First letter to Uppercase
	$title = lcfirst($title) # First letter to lowercase
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a commentScript error: local_191781.xml is not writable. Please set write permissions on local_191781.xml.