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. IE的Cookie目录和临时缓存目录的关系

    1.IE的Cookie位置注册表设置: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folde ...

  2. [转载]通过jQuery的attr修改onclick

    var js = "alert('B:' + this.id); return false;"; // creates a function from the "js&q ...

  3. FZU 2104 (13.11.28)

    Problem 2104 Floor problem Accept: 376    Submit: 433 Time Limit: 1000 mSec    Memory Limit : 32768 ...

  4. Python:urllib和urllib2的区别(转)

    原文链接:http://www.cnblogs.com/yuxc/ 作为一个Python菜鸟,之前一直懵懂于urllib和urllib2,以为2是1的升级版.今天看到老外写的一篇<Python: ...

  5. Linux下对后台进程通过kill传递信号不起作用的问题

    在阅读APUE信号一章时,我遇到Linux下对后台进程通过kill传递信号不起作用的问题 具体情形与如下链接中的老兄一致: http://bbs.csdn.net/topics/390335913?p ...

  6. 将.lib库文件转换成.a库文件的工具

    分享如下两个链接: 微盘: http://vdisk.weibo.com/s/ztzPTJIC52mz2 百度云盘: http://pan.baidu.com/s/11gTOc 使用方法,解压文件mi ...

  7. 在GDB 中如何记录 instruction-history and function-call-history

    (EDIT: per the first answer below the current "trick" seems to be using an Atom processor. ...

  8. spring mvc DispatcherServlet详解之二---request通过Controller获取ModelAndView过程

    整个spring mvc的架构如下图所示: 上篇文件讲解了DispatcherServlet通过request获取控制器Controller的过程,现在来讲解DispatcherServletDisp ...

  9. iOS-C文件添加到iOS项目中,运行报错

    iOS-C文件添加到iOS项目中,运行报错 问题: 往项目中添加一个空的c文件, 编译运行; 出现2,30个编译错误. 原因: 由于在项目中添加了Pch文件,在文件中所有代码还没有开始运行之前, pc ...

  10. iOS-系统定位功能

    ios系统定位 前期准备 系统定位功能,需要用到框架:CoreLocation/CoreLocation.h, 然后导入文件#import <CoreLocation/CoreLocation. ...