Strange results from IndexOf on German string

我只是一个虾纸丫 提交于 2019-12-08 16:04:45

问题


I have string "Ärger,-Ökonom-i-Übermut-ẞ-ß" and when I run IndexOf("--") I get a result of 23. If I use Replace on same string nothing gets replaced.

I don't understand what is happening, so can someone please shed some light on this issue? Application Culture is set on Croatian, it's not German, and framework version is 3.5.

Changing culture to German (de-DE) doesn't change this strange behavior.

Here is the screenshot from the debugger:


回答1:


Since Mr Lister doesn't want his well deserved upvotes, I will paste his comment here, and accept answer.

I'm afraid that U+1E9E is undefined according to .NET 3.5, because this character didn't exist in Unicode 4.0 (or whatever version of Unicode .NET 3.5 uses). It's a fairly new addition (uppercase version of German ß). So the IndexOf function ignores it. If you have any control over the text, you could change the character to ß or SS, whatever is more appropriate. Of course the better solution is to upgrade .NET to v4.0!




回答2:


IndexOf uses the current culture if you don't tell it otherwise:

This method performs a word (case-sensitive and culture-sensitive) search using the current culture.

Replace uses an ordinal comparison:

This method performs an ordinal (case-sensitive and culture-insensitive) search to find oldValue.



来源:https://stackoverflow.com/questions/9260693/strange-results-from-indexof-on-german-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!