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

前端 未结 5 1341
心在旅途
心在旅途 2021-01-18 05:47

I am trying following code

String s1 = \"ß.cfg\";
System.out.println (s.toUpperCase());

output I am getting is SS.CFG since U

5条回答
  •  耶瑟儿~
    2021-01-18 06:28

    "ß" 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', 'ß'));
    

提交回复
热议问题