What is the best approach to capitalize words in a string?
I have a sequence of strings which I get in following format:
As you can see middle section of the string is not consistent case (for Corolloa, it is listed as toyota). I need to change above as follows:
I want to make middle section of the string to be Title Case.
I am using following
static TextInfo textInfo = new CultureInfo( "en-US" ).TextInfo;
and using .ToTitleCase but the issue with TitleCase is if the string is in UPPERCASE, it would not change to TitleCase. Do we know how to handle a case when string is uppercase.
How do I make the first letter of a string uppercase, but not change the case of any of the other letters?
"this is a test"->
"This is a test"
"the Eiffel Tower"->
"The Eiffel Tower"
I am using Java to get a
String input from the user. I am trying to make the first letter of this input capitalized.
I tried this:
String name;BufferedReader br = new InputStreamReader(System.in);String s1 = name.charAt(0).toUppercase());System.out.println(s1 + name.substring(1));
which led to these compiler errors:
Type mismatch: cannot convert from InputStreamReader to BufferedReader
Cannot invoke toUppercase() on the primitive type char
This question already has an answer here:
How can I capitalize the first letter of a string using Angular or typescript?