java replace German umlauts

后端 未结 8 786
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 06:24

I have the following problem. I am trying to replace german umlauts like ä, ö, ü in java. But it simply does not work. Her

8条回答
  •  既然无缘
    2020-12-31 07:13

    This finally worked for me:

    private static String[][] UMLAUT_REPLACEMENTS = { { new String("Ä"), "Ae" }, { new String("Ü"), "Ue" }, { new String("Ö"), "Oe" }, { new String("ä"), "ae" }, { new String("ü"), "ue" }, { new String("ö"), "oe" }, { new String("ß"), "ss" } };
    public static String replaceUmlaute(String orig) {
        String result = orig;
    
        for (int i = 0; i < UMLAUT_REPLACEMENTS.length; i++) {
            result = result.replace(UMLAUT_REPLACEMENTS[i][0], UMLAUT_REPLACEMENTS[i][1]);
        }
    
        return result;
    }
    

    So thanks to all your answers and help. It finally was a mixture of nafas(with the new String) and Joop Eggen(the correct replace-Statement). You got my upvote thanks a lot!

提交回复
热议问题