-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StringComparer not working as expected on Linux #20599
Comments
this can be by design as we are using the OS for such features. I'll need to look first if there is anything else missing in our wrappers. |
I'm afraid the problem is wider. ladies, gentlemen ... behold:
env details
|
setting the culture at the beginning of the program fixes the issue
|
@ChristophB125 you can use the CompareOptions.IgnoreNonSpace to get comparison of "ß" evaluated as equal to "ss". CompareOptions can be passed to string APIs, CompareInfo APIs and also you can create StringComparer in 2.1 version using the following code: string sb = "ß";
string ss = "ss";
StringComparer sc1 = StringComparer.Create(CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace);
Console.WriteLine(sc1.Compare(sb, ss)); @migajek en_US_POSIX is very special locale and its string sorting behavior is special too. This is why you got this surprising result when you used it. switching to en-US as you did will give you the logical results. |
I am closing this issue, feel free to send any more questions or issue. thanks all. |
@tarekgh so the right question is .. why does .net core detect current culture as en-US-POSIX? LANG env variable is en_US.UTF-8 ...
|
You may look at https://github.com/dotnet/coreclr/blob/master/src/corefx/System.Globalization.Native/locale.cpp#L123 for how we get the default user locale. in short, we call ICU function |
you may check the values of the environment variables LC_MESSAGES and LC_ALL in your system. |
@tarekgh thank you, this seems to work as expected then as |
The following test works on Windows but not on Linux (RHEL 7.2 or Ubuntu 16.04):
Assert.AreEqual(0, StringComparer.CurrentCultureIgnoreCase.Compare("ss", "ß"));
Our Microsoft consultant Ben Gimblett has confirmed it and requested that we raise it as an issue here for follow-up.
We understand that .Net Core uses Windows's own comparison service, which is not available on Linux operating systems. How would one perform these culture aware operations on .Net core - irrespective of operating system?
The text was updated successfully, but these errors were encountered: