How can I capitalize the first letter of each word?

前端 未结 20 2331
暖寄归人
暖寄归人 2021-01-14 12:31

I need a script in any language to capitalize the first letter of every word in a file.

Thanks for all the answers.

Stackoverflow rocks!

20条回答
  •  伪装坚强ぢ
    2021-01-14 12:38

    A simple perl script that does this: (via http://www.go4expert.com/forums/showthread.php?t=2138)

    sub ucwords {
      $str = shift;
      $str = lc($str);
      $str =~ s/\b(\w)/\u$1/g;
      return $str;
    }
    
    while () {
        print ucwords $_;
    }
    

    Then you call it with

    perl ucfile.pl < srcfile.txt > outfile.txt
    

提交回复
热议问题