StringComparison not working in Linux (Kubernates) environment

Elaya Raja 96 Reputation points
2022-11-23T09:17:50.327+00:00

Hi Team,

The following comparison gets different results in windows env and Linux env.

string sb = "EÖALE";
string ss = "EöALE";
CultureInfo`.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
StringComparer sc1 = StringComparer.Create(CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace);
log($"Compare :{sc1.Compare(sb, ss)} \n");// OutPut 108
string s1 = "EÖALE";
string s2 = "EöALE";
bool currentCultureIgnoreCaseEquality = string.Equals(s1, s2, StringComparison.CurrentCultureIgnoreCase);
//OutPut false in linux

bool equality = string.Equals(s1, s2); //OutPut false in linux
bool ordinalIgnoreCaseEquality = string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase);//OutPut false in linux
bool InvariantCultureIgnore = string.Equals(s1, s2, StringComparison.InvariantCultureIgnoreCase);//OutPut false in linux

How to achieve to get true this comparison in Linux environment
I am using Dotnet core
Thanks in Advance

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,415 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,126 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Elaya Raja 96 Reputation points
    2022-11-28T05:34:26.98+00:00

    I found the solution here. It seems this issue was resolved in .net 6, and the other below versions have this issue.

    https://learn.microsoft.com/en-us/dotnet/core/compatibility/globalization/6.0/culture-creation-invariant-mode?source=recommendations

    0 comments No comments