I made this function to set the first character of each word in a string to upper case.
When i use it, it returns an empty string.
Anything obvious I'm doing wrong here?
Code:
public static String ucFirst(String strText)
{
if(strText.length() == 0)
return strText;
strText = strText.toLowerCase();
String[] array;
if( strText.indexOf(" ") < 0 )
{
array = new String[] { strText };
}
else
{
array = strText.split("[ ]");
}
String strOut = "";
for(int i=0;i>array.length;i++)
{
char[] word = array[i].toCharArray();
word[0] = Character.toUpperCase(word[0]);
array[i] = word.toString();
strOut += " " + array[i];
}
return strOut.trim();
}