本文介绍了使用InvariantCultureIgnoreCase而不是ToUpper用于不区分大小写的字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在,评论者写道:

不要使用 .ToUpper 以确保比较字符串不区分大小写。

Do NOT ever use .ToUpper to insure comparing strings is case-insensitive.

而不是:

type.Name.ToUpper() == (controllerName.ToUpper() + "Controller".ToUpper())) 
type.Name.Equals(controllerName + "Controller", 
     StringComparison.InvariantCultureIgnoreCase)

Why is this way preferred?

推荐答案

这是详细的答案。(阅读 3

Here is the answer in details .. The Turkey Test (read section 3)

修复:同样,使用序数(原始字节)
比较器或不变文化进行
比较,除非你绝对需要
基于文化的语言
比较(在土耳其给出大写
I的点)

Fix: Again, use an ordinal (raw byte) comparer, or invariant culture for comparisons unless you absolutely need culturally based linguistic comparisons (which give you uppercase I's with dots in Turkey)

微软你不应该使用Invariant ...但是Ordinal ...(

And according to Microsoft you should not even be using the Invariant... but the Ordinal... (New Recommendations for Using Strings in Microsoft .NET 2.0)

这篇关于使用InvariantCultureIgnoreCase而不是ToUpper用于不区分大小写的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 00:29