How do I capitalise the first letter of every sentence in a string? Should I use .capitalisedString
?
Capitalise first letter of every sentence
446 Views Asked by Tom Coomer At
2
There are 2 best solutions below
1

public static void main(String[] args) {
String a = "this is.a good boy";
String[] dot = a.split("\\.");
int i = 0;
String output = "";
while (i < dot.length) {
dot[i] = String.valueOf(dot[i].charAt(0)).toUpperCase()
+ dot[i].substring(1);
output = output + dot[i] + ".";
i++;
}
System.out.println(output);
}
You can enumerate
String
per sentences by usingNSStringEnumerationOptions.BySentences
. But it detect a "sentence" only if the first character is upper-cased.So, This may not be perfect, but you can try this: