How can I capitalize the first letter of each word?

前端 未结 20 2342
暖寄归人
暖寄归人 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:35

    Scala:

    scala> "hello world" split(" ") map(_.capitalize) mkString(" ")
    res0: String = Hello World
    

    or well, given that the input should be a file:

    import scala.io.Source
    Source.fromFile("filename").getLines.map(_ split(" ") map(_.capitalize) mkString(" "))
    

提交回复
热议问题