Connecting Tech Pros Worldwide Forums | Help | Site Map

how to replace each first letter of a word into capital letter :

Member
 
Join Date: Jan 2008
Posts: 48
#1: Sep 14 '09
Hi all, i'm currently struggling to perform the above mentioned replacement.

i already know how to catch the first letter in each word and determined if it's regular or capital.

however, i don't know how to replace this letter with it's corresponding capital letter.

perhaps there is an option to change the ascii value of the a character in perl regexp ?

for example :

Hello hello word --> Hello Hello World

many thanks for your help.

Newbie
 
Join Date: Sep 2009
Location: earth
Posts: 3
#2: Sep 14 '09

re: how to replace each first letter of a word into capital letter :


Expand|Select|Wrap|Line Numbers
  1. my $t="hello hello word";
  2. $t=~s/(\b)(\w)/$1\u$2/g;
  3. print $t;
  4.  
Member
 
Join Date: Jan 2008
Posts: 48
#3: Sep 14 '09

re: how to replace each first letter of a word into capital letter :


hey, thanks for the help ! i really appreciate it.
can you explain what does the '\u' symbol means, i haven't found it in any perl documentation
Newbie
 
Join Date: Sep 2009
Location: earth
Posts: 3
#4: Sep 14 '09

re: how to replace each first letter of a word into capital letter :


perldoc perlre

...
\u uppercase next char (think vi)
...
Member
 
Join Date: Jan 2008
Posts: 48
#5: Sep 14 '09

re: how to replace each first letter of a word into capital letter :


thanks again, i found all i need (and much more) in perlre
Reply

Tags
capital letter, regexp


Similar Perl bytes