Posted By

darkapple on 06/16/09


Tagged

title case


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ozone
brianegge


String in Title case


 / Published in: Java
 

URL: http://www.theeggeadventure.com/wikimedia/index.php/Java_Proper_Case

  1. static String properCase(String s) {
  2. Pattern p = Pattern.compile("(^|\\W)([a-z])");
  3. Matcher m = p.matcher(s.toLowerCase());
  4. StringBuffer sb = new StringBuffer(s.length());
  5. while(m.find()) {
  6. m.appendReplacement(sb, m.group(1) + m.group(2).toUpperCase() );
  7. }
  8. m.appendTail(sb);
  9. return sb.toString();
  10. }

Report this snippet  

You need to login to post a comment.