问题描述
我需要比较德语两个字符串来检查,如果他们是平等的,只有在使用umlaute不同。例如。 约尔格应该是一样的约尔格
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".
所以,我想:
var ci = new CultureInfo("de-DE");
int compareResult = ci.CompareInfo.Compare("jörg", "joerg", CompareOptions.IgnoreNonSpace);
以及
as well as
int compareResult = String.Compare("jörg", "joerg", true, ci);
(或者是这两个相等呢?)
(or are those two equal anyway?)
但是,这并不工作,将返回 1
。这是所有变音符号ö,ü和一个相同的。如果我比较大街
和大街
以同样的方式,这样做的工作并返回 0
?
However, this does not work and will return 1
. It is the same for all umlauts ö,ü and ä. If I compare strasse
and straße
in the same way, this does work and returns 0
?!
感谢您的任何想法!这表明,煤矿应该工作。
Thanks for any ideas! This post suggests that mine should work.
推荐答案
我有同样的问题,发现再没有其他的解决方案替换它们如通过扩展。据我所知,对此没有直接的解决方案。
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
这篇关于对于Umlaute文化意识的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!