converting ß.cfg to upper case using toUpperCase() in java

"ß" 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


The Java implementation is simply following what the Unicode specification says. And Unicode says this:

# ================================================================================
# Unconditional mappings
# ================================================================================

# The German es-zed is special--the normal mapping is to SS.
# Note: the titlecase should never occur in practice. It is equal to titlecase(uppercase(<es-zed>))

00DF; 00DF; 0053 0073; 0053 0053; # LATIN SMALL LETTER SHARP S

Reference: http://unicode.org/Public/UNIDATA/SpecialCasing.txt

If you want to implement a form of uppercase conversion that is different to Unicode, you'll need to specify and implement it yourself.


(If you want to see a bunch of people getting hot under the collar about "uppercase ß", read this email thread - http://unicode.org/mail-arch/unicode-ml/y2007-m05/0007.html )

Tags:

Java