Created
October 15, 2017 20:00
-
-
Save ponnamkarthik/90822962944a8fe765524159c476495e to your computer and use it in GitHub Desktop.
Convert Text to Titlecase in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String toTitleCase(String str) | |
{ | |
String[] words = str.trim().split(" "); | |
StringBuilder ret = new StringBuilder(); | |
for(int i = 0; i < words.length; i++) | |
{ | |
if(words[i].trim().length() > 0) | |
{ | |
Log.e("words[i].trim",""+words[i].trim().charAt(0)); | |
ret.append(Character.toUpperCase(words[i].trim().charAt(0))); | |
ret.append(words[i].trim().substring(1)); | |
if(i < words.length - 1) { | |
ret.append(' '); | |
} | |
} | |
} | |
return ret.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment