I am trying following code
String s1 = "ß.cfg";
System.out.println (s.toUpperCase());
output I am getting is SS.CFG
since Unicode didn't define an uppercase version of ß while I want the output as ß.CFG
.
Is there any way I can achieve that?
Description. The toUpperCase() method returns the value of the string converted to uppercase. This method does not affect the value of the string itself since JavaScript strings are immutable.
Java String toUpperCase() Method The toUpperCase() method converts a string to upper case letters.
Return Value It returns the String, converted to uppercase.
"ß" character is equivalent to "ss" (used in German, for example), and this is defined so in your Locale (the Locale you are using in your app).
You can try to do some experiment with a different Locale using method:
toUpperCase(Locale locale)
Edit: As the user said, this method is not valid, a possible workaroud (not very elegant) is:
String s1 = new String ("auß.cfg").replace('ß', '\u9999');
System.out.println (s1.toUpperCase(Locale.UK).replace('\u9999', 'ß'));
The documentation for toUpperCase( Locale )
explicitly states that this is what will happen:
Since case mappings are not always 1:1 char mappings, the resulting String may be a different length than the original String.
small letter sharp s -> two letters: SS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With