Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Equals GID returning false?

I have the following C# code in my ASP.NET MVC application. I try to compare 2 string using the Equals method, with culture = "vi". My code below:

string culture = "vi";

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentUICulture = 
  System.Threading.Thread.CurrentThread.CurrentCulture;

var CCC = string.Equals("CategId", "CATEGID", StringComparison.CurrentCultureIgnoreCase);
var xx = string.Equals("TestGID", "TestGID", StringComparison.CurrentCultureIgnoreCase);
var zz = string.Equals("id", "ID", StringComparison.CurrentCultureIgnoreCase);

Results:

CCC = false;

xx = true;

zz = true;

I don't know why CCC is false. Is there anything wrong? If I set culture = id, ko, en, etc... then CCC = true. Who can help me?

like image 549
Hong Van Vit Avatar asked Sep 25 '17 07:09

Hong Van Vit


People also ask

Is it possible for equals () to return false?

Yes. You can also override the equals() method and play with it.

Can you use != For strings?

Note: When comparing two strings in java, we should not use the == or != operators. These operators actually test references, and since multiple String objects can represent the same String, this is liable to give the wrong answer.

What does str1 == str2 return?

The method str1. compareTo(str2) would return: A positive value, if str1 is lexicographically greater than str2. 0, if str1 is equal to str2.

Is equals () the same as ==?

The main difference between the . equals() method and == operator is that one is a method, and the other is the operator. We can use == operators for reference comparison (address comparison) and . equals() method for content comparison.


1 Answers

It is gI which is not equal to GI in case of Vietnamese language. gi (GI) is syllable-initial, kind of one letter while gI are two separate letters. Other pairs are

cH != CH
kH != KH
nG != NG
nH != NH
pH != PH
qU != QU
tH != TH
tR != TR

https://en.wikipedia.org/wiki/Vietnamese_language

like image 134
Dmitry Bychenko Avatar answered Sep 27 '22 18:09

Dmitry Bychenko