Culture-aware string comparison for Umlaute

后端 未结 1 343
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 22:31

I need to compare two strings in German language to check if they are equal and only differ in the use of umlaute. E.g. \"Jörg\" should be the same as \"Joerg\".

So

相关标签:
1条回答
  • 2021-01-12 23:30

    I had the same issue and found no other solution then replacing them e.g. by a extension. As far as i know there is no "direct" solution for this.

    public static string ReplaceUmlaute(this string s) 
    {
        return s.Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("Ä", "AE").Replace("Ö", "OE").Replace("Ü", "UE");
    }
    

    Result:

    int compareResult = String.Compare("jörg".ReplaceUmlaute(), "joerg", true, ci); // 0
    
    0 讨论(0)
提交回复
热议问题