String in Title case


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.