Setting Turkish and English locale: translate Turkish characters to Latin equivalents

前端 未结 5 1101
别跟我提以往
别跟我提以往 2021-02-04 02:29

I want to translate my Turkish strings to lowercase in both English and Turkish locale. I\'m doing this:

String myString=\"YAŞAT BAYRI\";
Locale trlocale= new Lo         


        
5条回答
  •  伪装坚强ぢ
    2021-02-04 03:32

    If you just want the string in ASCII, without accents, the following might do. First an accented character might be split in ASCII char and a combining diacritical mark (zero-width accent). Then only those accents may be removed by regular expression replace.

    public static String withoutDiacritics(String s) {
        // Decompose any ş into s and combining-,.
        String s2 = Normalizer.normalize(s, Normalizer.Form.NFD);
        return s2.replaceAll("(?s)\\p{InCombiningDiacriticalMarks}", "");
    }
    

提交回复
热议问题