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?
Yes. You can also override the equals() method and play with it.
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.
The method str1. compareTo(str2) would return: A positive value, if str1 is lexicographically greater than str2. 0, if str1 is equal to str2.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With