Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Whitespace decimal values:
- // 09, HORIZONTAL TABULATION. 10, LINE FEED. 11, VERTICAL TABULATION.
- // 12, FORM FEED. 13, CARRIAGE RETURN.
- // 28, FILE SEPARATOR. 29, GROUP SEPARATOR. 30, RECORD SEPARATOR.
- // 31, UNIT SEPARATOR. 32, SPACE.
- public static String toCapitalCase(String str) {
- boolean capitalize = true;
- char[] cha = str.toCharArray();
- char ch;
- for (int i = 0; i < cha.length; i++) {
- ch = cha[i];
- if (ch >= 'a' && ch <= 'z' && capitalize) {
- cha[i] = (char) (ch - 32);
- capitalize = false;
- } else if (ch >= 'A' && ch <= 'Z' && !capitalize) {
- cha[i] = (char) (ch + 32);
- } else {
- if ((ch >= 9 && ch <= 15) || (ch >= 29 && ch <= 32))
- capitalize = true;
- }
- }
- return new String(cha);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement