C# String.Equals GID返回false?
我的ASP.NET MVC应用程序中有以下C#代码。我尝试使用C# String.Equals GID返回false?,c#,asp.net,string,localization,C#,Asp.net,String,Localization,我的ASP.NET MVC应用程序中有以下C#代码。我尝试使用Equals方法将2string与culture=“vi”进行比较。我的代码如下: string culture = "vi"; System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); System.Threading.Thread.CurrentThread.CurrentUICulture = Sy
Equals
方法将2string
与culture=“vi”
进行比较。我的代码如下:
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);
结果:
CCC=错误
xx=真
zz=真
我不知道为什么
CCC
是false
。有什么问题吗?如果我设置了culture=id、ko、en
等。。。然后CCC=true
。谁能帮我?在越南语的情况下,gI
不等于gI
gi
(gi
)是音节首字母,类似于一个字母,而gi
是两个独立的字母。其他对是
cH != CH
kH != KH
nG != NG
nH != NH
pH != PH
qU != QU
tH != TH
tR != TR
你可以试试
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.InvariantCultureIgnoreCase);
var CCC1 = string.Equals("CategId", "CATEGID", StringComparison.CurrentCultureIgnoreCase);
在这种情况下,由于文化原因,
CCC
将返回true
,但CCC1
将返回false
。根据您的区域性,GID
和GID
是不同的。这会引发一个例外:区域性“vi”是中性区域性。它不能用于格式化和解析,因此不能设置为线程的当前区域性。
对于非GUI应用程序,需要使用vi VN
(尽管这仍将返回false
),而应使用StringComparer Comparer=StringComparer.Create(new-CultureInfo(“vi VN”),true); 比较器等于(“CategId”、“CategId”)代码>这是因为当前的区域性比较慢。由于您正在比较的字符串在英语或类似英语中是“清晰的”(对于“清晰”的某些值),因此,正如Kevin所建议的,您应该使用InvariantCultureInoRecase
。当有人使用土耳其语触发问题时,我们在“设置名称”方面遇到了类似的问题,SID
不再等于SID
,即使忽略大小写也是如此。