I know this way
val str=org.apache.commons.lang.WordUtils.capitalizeFully("is There any other WAY"))
Want to know is there any other way to do the Same.
something in Scala Style
I know this way
val str=org.apache.commons.lang.WordUtils.capitalizeFully("is There any other WAY"))
Want to know is there any other way to do the Same.
something in Scala Style
Capitalize the first letter of a string:
"is There any other WAY".capitalize
res8: String = Is There any other WAY
Capitalize the first letter of every word in a string:
"is There any other WAY".split(' ').map(_.capitalize).mkString(" ")
res9: String = Is There Any Other WAY
Capitalize the first letter of a string, while lower-casing everything else:
"is There any other WAY".toLowerCase.capitalize
res7: String = Is there any other way
Capitalize the first letter of every word in a string, while lower-casing everything else:
"is There any other WAY".toLowerCase.split(' ').map(_.capitalize).mkString(" ")
res6: String = Is There Any Other Way
This one will capitalize every word regardless of the separator and doesn't require any additional libraries. It will also handle apostrophe correctly.
scala> raw"\b((?<!\b')\w+)".r.replaceAllIn("this is a test, y'all! 'test/test'.", _.group(1).capitalize)
res22: String = This Is A Test, Y'all! 'Test/Test'.
To capitalize the first letter of every word despite of a separator:
scala> import com.ibm.icu.text.BreakIterator
scala> import com.ibm.icu.lang.UCharacter
scala> UCharacter.toTitleCase("is There any-other WAY", BreakIterator.getWordInstance)
res33: String = Is There Any-Other Way