ToUpperInvariant使用不依赖于区域性进行转换,而ToUpper则使用了当前线程的CultureInfo,进行转换,所以性能会有所影响,以下为测试:

         [Test]
public void TestInvariant()
{
Int32 count = * ;
Stopwatch watch = new Stopwatch(); String str = "abcdefghijklmnopqrstuvwxyz中华人民共和国";
watch = Stopwatch.StartNew();
for (int i = ; i < count; i++)
{
str.ToUpperInvariant();
}
Console.WriteLine("ToUpperInvariant:{0}", watch.Elapsed.ToString());
} [Test]
public void TestNoInvariant()
{
Int32 count = * ;
Stopwatch watch = new Stopwatch(); String str = "abcdefghijklmnopqrstuvwxyz中华人民共和国";
watch = Stopwatch.StartNew();
for (int i = ; i < count; i++)
{
str.ToUpper();
}
Console.WriteLine("ToUpper:{0}", watch.Elapsed.ToString());
}

ToUpperInvariant:00:00:00.2980660

ToUpper:00:00:00.3281423

如果 确认当前的比较和区域性无关的话,推荐使用ToUppperInvariant

使用ToUpperInvariant避免使用ToUpper的更多相关文章

  1. C函数tolower,与toupper

    tolower    将大写转换成小写.  非字母字符不做出处理.   这个函数用法有点特殊他是处理字符的,而不是处理字符串的. 所谓的不能处理字符串不是说他不能处理字符串,他处理的时候对字符串必须是 ...

  2. 尽量使用ToUpper比较,避免使用ToLower

    在编码时尽量使用ToUpper比较,避免使用ToLower,因为微软对ToUpper进行了优化,以下为测试结果: public void TestToLower() { Stopwatch watch ...

  3. toupper函数及一些小程序

    toupper 原型:extern int toupper(int c); 用法:#include <ctype.h> 功能:将字符c转换为大写英文字母 说明:如果c为小写英文字母,则返回 ...

  4. (stringstream toupper 空格) 词组缩写 hdu2564

    词组缩写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. 字符串转换atof atoi atol gcvt strtod strtol strto ul toascii tolower toupper

    atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoul 表头文件 #include <stdlib.h> 定义函数 double at ...

  6. linu 把文件中的字母小写转换为大写,大写转换为小写awk toupper tolower

    cat aa.txt|tr "[a-z]" "A-Z" [root@ob2 mytmp]# awk '{print toupper($0)}' aa2.txt ...

  7. R语言改变大小写 toupper()和 tolower()函数

    这些函数改变字符串的字符的大小写. 语法 toupper()和 tolower()函数的基本语法为: toupper(x) tolower(x) 以下是所使用的参数的说明: x - 向量输入. 示例 ...

  8. About toupper()

    // toupper.c #include <stdio.h> #include <string.h> #include <ctype.h> int main() ...

  9. ccf 201409-3 字符串匹配(toupper,tolower)

     ccf 201409-3 字符串匹配(toupper,tolower) 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行.你的程序还需支持大小写敏感选项:当选项打开时,表示同一 ...

随机推荐

  1. 找出Active Directory架构操作主机方法!

  2. UVaLive4043 UVa1411 Ants 巨人与鬼

    题意:给出平面上n个白点n个黑点,要求两两配对,且配对所连线段没有交点. 法一:暴力 随机一个初始方案,枚举任意两条线段如果有交点就改一下. 效率其实挺好的. 法二:二分图最佳完美匹配 显然没有交点的 ...

  3. SQL Server 中关于EXCEPT和INTERSECT的使用方法

    熟练使用SQL Server中的各种使用方法会给查询带来非常多方便.今天就介绍一下EXCEPT和INTERSECT.注意此语法仅在SQL Server 2005及以上版本号支持. EXCEPT是指在第 ...

  4. mysql使用硬链接配合truncate 删除2.2T的表 --杨奇龙

    http://blog.csdn.net/wyzxg/article/details/8626814 http://blog.itpub.net/22664653/viewspace-750408/ ...

  5. Java语言基础(六)

    Java语言基础(六) 前一章提到的, BigDecimal, DecimalFormat等具体用法,这里就不在说了,网上有许多 一.下面让我们看一个例子(自由落体运动位移) 说明: (1).公式是 ...

  6. Objective-C通过联合存储为类增加属性及原理解析

    联合存储实现方式及底层原理解析 作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory_tjsd/article/details/9347981 转载请注明出处 ...

  7. [转] git修改author

    Changing author info To change the name and/or email address recorded in existing commits, you must ...

  8. [转] 用管道获得shell 命令的输出

    用管道: 通过fgets(buf, n, ptr)buf就可以得到命令“ps -ef"一样的信息, 读帮助”man popen": char *cmd = "ps -ef ...

  9. 函数返回一个SqlDataReader对象

    解决方法: 1.尝试使用dataset 2.执行数据库操作命令 SqlDataReader reader=mySqlCommand.ExecuteReader(CommandBehavior.Clos ...

  10. Datum Form Goole Android

    1. <TurboChargeYourUI-How to make your AndroidUI fast and efficient> 2. <The World of List ...