My exceptions are:
- Capital letter at the beginning of the sentence or after a punctuation mark
- Add space after punctuation mark
- After an abbreviation, don't use capital letters
- After a "- " (with a space), use capital letters
- After a "-" (no space), don't capitalize
My code below with the exceptions:
private static char[] PUNCTUATION_MARKS = { '?', '!', ';', '.', '-' };
applyCorrectCase("step 1 - take your car");
applyCorrectCase("reply-to address");
applyCorrectCase("req. start");
applyCorrectCase("alt. del. date [alternate detection date]");
applyCorrectCase("you are.important for us? to continue?here! yes");
String applyCorrectCase(String value) {
String lowerCaseValue = value.toLowerCase();
if (value.contains(". ")) {
lowerCaseValue = value.replace(". ", ".");
}
lowerCaseValue = WordUtils.capitalize(lowerCaseValue, PUNCTUATION_MARKS );
System.out.println(lowerCaseValue.replace(".", ". "));
}
These are my result:
Step 1 - take your car <--- The 't' after the '-' need to be uppercase
Reply-To address <--- The 't' after the '-' need to be lowercase
Req. Start <--- The 's' after the '.' need to be lowercase because it is an abbreviation
Alt. Del. Date [alternate detection date] <--- Both 'd' after the '.' need to be lowercase because it is an abbreviation
You are. Important for us? to continue?Here! yes <--- The 't' after the '?' need to be capital, we need to add an space between '?' and 'H', the 'y' after the '!' need to be uppercase
These are my expectations:
Step 1 - Take your car
Reply-to address
Req. start
Alt. del. date [alternate detection date]
You are. Important for us? To continue? Here! Yes
Any idea to fix my code?
UPDATE
About the code if (value.contains(". ")) {
and System.out.println(lowerCaseValue.replace(".", ". "));
I did these before I had more punctuation marks to check, now that I have more it doesn't work