Is there a term for replacing regular expressions for a uppercase or lowercase version of a backlink?

Suppose I want to change the string string to "header"; where the first letter of each word is capitalized. Can this be done using a single call to replaceAll() with a modifier in the replacement expression?

For example,

 str = str.replaceAll("\\b(\\S)", "???$1"); 

Where is the "???" this is some expression that adds up to the case of the next letter.

I saw that these are other tools (e.g. text panel) where \U will stack the next letter in upper case.

?

+7
java string regex replace uppercase
source share
1 answer

Unable to replace replaceAll. But you can use regex and split:

 public String titleTextConversion(String text) { String[] words = text.split("(?<=\\W)|(?=\\W)"); StringBuilder sb = new StringBuilder(); for (String word : words) { if (word.length() > 0) sb.append(word.substring(0, 1).toUpperCase()).append(word.substring(1).toLowerCase()); } return sb.toString(); } 
+2
source share

All Articles