2

Before marking my question as duplicate, notice that there is a fundamental misunderstanding in that thread as to what "title case" means. In the english language, Title Case is not the same as having each word capitalized. In a title, we should

  • Capitalize nouns, pronouns, adjectives, verbs, adverbs, and subordinate conjunctions.
  • Lowercase articles (a, an, the), coordinating conjunctions, and prepositions.

Since the similar question I am pointing to is also a bit dated, I was wondering if anyone is aware of any facility in android to convert a string to a title case? Or is the only option to roll out my own class?

For some background if you care, I am building an app that has some user generated contents, in addition to expert generated contents. I want my app to look intelligent and professional. So for the EditText I enable textAutoComplete|textAutoCorrect. But in addition, I want the title to look like titles, not just strings that have been typed by random users.

Community
  • 1
  • 1
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • Funny. In German, you should only capitalize Nouns and personal Names (first, last and middle if any). And the first Letter after the Mark (of course). As shown in this Sentence. Jokes apart, this post on codereview might be of some interest... or is it? http://codereview.stackexchange.com/questions/100832/java-port-of-titlecase – Phantômaxx Sep 29 '15 at 20:12
  • I'm afraid you'll have to write some code for this. – Christine Sep 29 '15 at 20:33

1 Answers1

4

It is very late answer but may be can help others.

public static String changeStringCase(String s) {

final String DELIMITERS = " '-/"; 

StringBuilder sb = new StringBuilder();
boolean capNext = true;

for (char c : s.toCharArray()) {
    c = (capNext)
            ? Character.toUpperCase(c)
            : Character.toLowerCase(c);
    sb.append(c);
    capNext = (DELIMITERS.indexOf((int) c) >= 0); 
}
return sb.toString(); }

Output will be

  1. cHANge caSE --> Change Case
  2. CHANGE CASE --> Change Case
  3. change case --> Change Case

etc..

Sandeep
  • 2,573
  • 3
  • 21
  • 28