Java String Sentence Case toSentenceCase(String original)

Here you can find the source of toSentenceCase(String original)

Description

to Sentence Case

License

Apache License

Declaration

public static String toSentenceCase(String original) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toSentenceCase(String original) {
        String[] lines = original.split("\\.");
        for (int i = 0; i < lines.length; i++) {
            lines[i] = toInitialCap(lines[i]);
        }//from   w w  w  .  ja v  a2 s .  c  om
        return join(lines, ".");
    }

    public static String toInitialCap(String original) {
        if (original.trim().length() == 0)
            return "";
        return original.substring(0, 1).toUpperCase() + original.substring(1).toLowerCase();
    }

    public static String join(String[] text, String appendChar) {
        StringBuffer sentance = new StringBuffer();
        for (int i = 0; i < text.length; i++) {
            sentance.append(text[i]);
            if (i != text.length - 1)
                sentance.append(appendChar);
        }
        return sentance.toString();
    }

    public static String toString(String[] arrStrs) {
        StringBuffer strBuf = new StringBuffer();
        for (int i = 0; i < arrStrs.length; i++) {
            strBuf.append(arrStrs[i] + ", ");
        }
        return strBuf.toString();
    }
}

Related

  1. toSentenceCase(final String s)
  2. toSentenceCase(String inputString)
  3. toSentenceCase(String s, char endOfLineSym)
  4. toSentenceCase(String str)
  5. toSentenceCase(String string)