How do i replace accents (german) in .NET

前端 未结 5 2140
有刺的猬
有刺的猬 2020-12-03 17:36

I need to replace accents in the string to their english equivalents

for example

ä = ae

ö = oe

Ö = Oe

ü = ue

I know to strip

5条回答
  •  天命终不由人
    2020-12-03 18:35

    Do just want a mapping of german umlauts to the two-letter (non-umlaut) variant? Here you go; untested, but it handles all german umlauts.

    String replaceGermanUmlauts( String s ) {
        String t = s;
        t = t.Replace( "ä", "ae" );
        t = t.Replace( "ö", "oe" );
        t = t.Replace( "ü", "ue" );
        t = t.Replace( "Ä", "Ae" );
        t = t.Replace( "Ö", "Oe" );
        t = t.Replace( "Ü", "Ue" );
        t = t.Replace( "ß", "ss" );
        return t;
    }
    

提交回复
热议问题