Sentence Capitalization with Java
April 18th, 2009Simple Java function to capitalize the first word of every sentence:
public static String capitalize(String content){
Pattern capitalize = Pattern.compile("([\\?!\\.] )([a-z])");
Matcher m = capitalize.matcher(content);
while (m.find()) {
content = m.replaceFirst(m.group(1) + m.group(2).toUpperCase());
m = capitalize.matcher(content);
}
return content;
}
If you have any suggestions on how to improve this method, leave a comment.

