Java String Title Case toTitleCase(String sIn)

Here you can find the source of toTitleCase(String sIn)

Description

to Title Case

License

Open Source License

Declaration

public static String toTitleCase(String sIn) 

Method Source Code

//package com.java2s;
/*/*  w ww  . ja v  a2 s . c  om*/
Copyright 2014 Michael K Martin
    
This file is part of Civet.
    
Civet is free software: you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Civet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the Lesser GNU General Public License
along with Civet.  If not, see <http://www.gnu.org/licenses/>.
*/

public class Main {
    public static String toTitleCase(String sIn) {
        StringBuffer sb = new StringBuffer();
        boolean bFirst = true;
        for (int i = 0; i < sIn.length(); i++) {
            char cNext = sIn.charAt(i);
            if (bFirst)
                cNext = Character.toUpperCase(cNext);
            else
                cNext = Character.toLowerCase(cNext);
            if (Character.isWhitespace(cNext))
                bFirst = true;
            else
                bFirst = false;
            sb.append(cNext);
        }
        return sb.toString();
    }
}

Related

  1. toTitleCase(String name)
  2. toTitleCase(String original)
  3. toTitleCase(String original)
  4. toTitleCase(String s)
  5. toTitleCase(String s)
  6. toTitleCase(String str)
  7. toTitleCase(String str)
  8. toTitleCase(String string)
  9. toTitleCase(String string)