Here you can find the source of toTitleCase2(String string, String separators)
Parameter | Description |
---|---|
string | a parameter |
separators | a parameter |
public static String toTitleCase2(String string, String separators)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w. ja va2 s . c o m * Convert a strong into an alternating form of each new word starting with a capital letter. * * @param string * @param separators * @return new string */ public static String toTitleCase2(String string, String separators) { char[] seps = separators.toCharArray(); char[] tempChar = string.toLowerCase().toCharArray(); boolean firstLetter = false; boolean hitSep = false; int i, j; // The first character is always upper cased tempChar[0] = Character.toUpperCase(tempChar[0]); // Loop through the rest of them for (i = 1; i < string.length(); i++) { if (firstLetter) { tempChar[i] = Character.toUpperCase(tempChar[i]); firstLetter = false; } else { // Check if we hit a separator for (j = 0; j < seps.length; j++) { if (tempChar[i] == seps[j]) { hitSep = true; break; } } if (hitSep) { tempChar[i] = ' '; firstLetter = true; hitSep = false; } } } return new String(tempChar); } }