Java String Sentence Case toSentenceCase(String s, char endOfLineSym)

Here you can find the source of toSentenceCase(String s, char endOfLineSym)

Description

to Sentence Case

License

Open Source License

Declaration

public static String toSentenceCase(String s, char endOfLineSym) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toSentenceCase(String s, char endOfLineSym) {
        s = s.toLowerCase();/*from  ww  w.j a  va2 s. co m*/

        int strl = s.length();
        char[] holder = new char[strl];
        boolean sentenceActive = true;

        int i = 0;
        while (i < strl) {
            char nextC = s.charAt(i);
            if (((sentenceActive) || (i == 0)) && (Character.isLetterOrDigit(nextC))) {
                nextC = Character.toUpperCase(nextC);
                sentenceActive = false;
            }

            if ((Character.getType(nextC) == 13) || (Character.getType(nextC) == 14) || (nextC == endOfLineSym)) {
                sentenceActive = true;
            }
            holder[i] = nextC;
            i++;
        }

        return new String(holder);
    }

    public static String toLowerCase(String s) {
        return s.toLowerCase();
    }

    public static String toUpperCase(String s) {
        return s.toUpperCase();
    }
}

Related

  1. toSentenceCase(final String s)
  2. toSentenceCase(String inputString)
  3. toSentenceCase(String original)
  4. toSentenceCase(String str)
  5. toSentenceCase(String string)