Gov*_*ngh 28 string scala capitalization
我知道这种方式
val str=org.apache.commons.lang.WordUtils.capitalizeFully("is There any other WAY"))
Run Code Online (Sandbox Code Playgroud)
想知道还有其他方法可以做同样的事.
Scala风格的东西
Mic*_*jac 110
大写字符串的第一个字母:
"is There any other WAY".capitalize
res8: String = Is There any other WAY
Run Code Online (Sandbox Code Playgroud)
将字符串中每个单词的首字母大写:
"is There any other WAY".split(' ').map(_.capitalize).mkString(" ")
res9: String = Is There Any Other WAY
Run Code Online (Sandbox Code Playgroud)
大写字符串的第一个字母,同时降低其他所有字母:
"is There any other WAY".toLowerCase.capitalize
res7: String = Is there any other way
Run Code Online (Sandbox Code Playgroud)
将字符串中每个单词的第一个字母大写,同时降低其他所有内容:
"is There any other WAY".toLowerCase.split(' ').map(_.capitalize).mkString(" ")
res6: String = Is There Any Other Way
Run Code Online (Sandbox Code Playgroud)
有点复杂,您可以使用split来获取字符串列表然后使用大写,然后使用reduce来获取字符串:
scala> "is There any other WAY".split(" ").map(_.capitalize).mkString(" ")
res5: String = Is There Any Other WAY
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21023 次 |
| 最近记录: |