question

ElayaRaja-3410 avatar image
0 Votes"
ElayaRaja-3410 asked ElayaRaja-3410 edited

StringComparison not working in Linux (Kubernates) environment

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

dotnet-csharpdotnet-runtimedotnet-standard
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you also try CompareOptions.IgnoreCase?


0 Votes 0 ·

@Viorel-1 Tried and for this also returned false in Kubernetes env.

0 Votes 0 ·

@ElayaRaja-3410, Welcome to Microsoft Q&A, based on my test, I get the true result in windows 10 environment. I am installing linux environment. what is your current linux environment?

0 Votes 0 ·
Show more comments

1 Answer

ElayaRaja-3410 avatar image
0 Votes"
ElayaRaja-3410 answered ElayaRaja-3410 edited

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.