java replace German umlauts

后端 未结 8 809
爱一瞬间的悲伤
爱一瞬间的悲伤 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:08

    If you use Apache Commons or Commons3 in your project, it would be most efficient to use a class like

    public class UmlautCleaner {
    
        private static final String[] UMLAUTE = new String[] {"Ä", "Ö", "Ü", "ä", "ö", "ü", "ß"};
        private static final String[] UMLAUTE_REPLACEMENT = new String[] {"AE", "OE", "UE", "ae", "oe", "ue", "ss"};
    
        private UmlautCleaner() {
        }
    
        public static String cleanSonderzeichen(final String s) {
            return StringUtils.stripAccents(StringUtils.replaceEach(s, UMLAUTE, UMLAUTE_REPLACEMENT));
        }
    }
    

提交回复
热议问题