Capitalize String Word Or Phrase
Capitalize the value of Word or a Phrase.
Javadoc available at https://www.javatapas.com/docs/javatapas/string/CapitalizeString.html
public static String capitalizeString(String inStr) {
if (inStr == null || inStr.trim().length() == 0) return inStr;
if (inStr.contains(" ")){return capitalizePhrase(inStr);}
else {return capitalizeWord(inStr);}
}
private static String capitalizeWord(String inStr) {
return inStr.substring(0, 1).toUpperCase() + inStr.substring(1).toLowerCase();
}
private static String capitalizePhrase(String inStr) {
StringBuilder sb = new StringBuilder();
String[] words = inStr.split("\\s");
for (String s : words) {sb.append(capitalizeWord(s) + " ");}
sb.delete(sb.length() - 1, sb.length());
return sb.toString();
}