I’ve looked all over for how to capitalize the first character of a string, but nothing I’ve found has helped. For my method to work, I need to set a user entered string to lower case.
sourceText = enterText.getText();
char chr = sourceText.charAt(0);
so I have a boolean that’s true if the first character is uppercase.
boolean upperCase = Character.isUpperCase(chr);
sourceTextLower = sourceText.toLowerCase();
Cool stuff happens here, and the final product is another string called translatedTextString and an if statement
String s2 = "";
if(upperCase == true)
{
int x = translatedTextString.length();
s2 = translatedTextString.substring(0,1).toUpperCase().concat(translatedTextString.substring(1, x));
}
//translatedText is a label
translatedText.setText(s2);
However, when I run the program, the first character of my result is still lower case. So my questions is: is this even the right way to go about doing this? If so, what am I doing wrong, and if not, how can I do it correctly?
It might be easier just to assume that the first letter is always lowercase, then you don’t need any checks: