fad3r wrote: > Hi again, > > I would like capitalize every 1st character of all the words in a > string. So something like please help me would become Please Help Me. > Recently people on this list were helpful enough to tell me about a > function called substr. I used this to successfully remove x amount > of characters from the beginning of a string. I am not sure if this > is the type of function I would use for what I want to accomplish or > is a regular expression better? > > What is the best method of matching and substituting?
Did you combine your man pages as I suggested? If so, you could search for 'capitalize.*word' or some such. If not have you tried using perldoc ? >From perlfaq4 man page. How do I capitalize all the words on one line? To make the first letter of each word upper case: $line =~ s/\b(\w)/\U$1/g; This has the strange effect of turning ""don't do it"" into ""Don'T Do It"". Sometimes you might want this. Other times you might need a more thorough solution (Suggested by brian d foy): $string =~ s/ ( (^\w) #at the beginning of the line | # or (\s\w) #preceded by whitespace ) /\U$1/xg; $string =~ /([\w']+)/\u\L$1/g; To make the whole line upper case: $line = uc($line); To force each word to be lower case, with the first letter upper case: $line =~ s/(\w+)/\u\L$1/g; You can (and probably should) enable locale awareness of those characters by placing a "use locale" pragma in your program. See perllocale for endless details on locales. This is sometimes referred to as putting something into "title case", but that's not quite accurate. Consider the proper capitalization of the movie *Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb*, for example. Damian Conway's Text::Autoformat module provides some smart case transformations: use Text::Autoformat; my $x = "Dr. Strangelove or: How I Learned to Stop ". "Worrying and Love the Bomb"; print $x, "\n"; for my $style (qw( sentence title highlight )) { print autoformat($x, { case => $style }), "\n"; } -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs