来源:http://www.codeproject.com/Tips/297011/How-to-Toggle-String-Case-in-NET#alternative22

使用LINQ:

public static string ToggleCase(this string str)
{
if (string.IsNullOrEmpty(str)) return str;
return string.Join("", (from i in str
select (char.IsLetter(i) ?
(char.IsUpper(i) ?
char.ToLower(i) :
char.ToUpper(i)) :
i).ToString()
).ToArray());
}

来源:http://www.oschina.net/code/snippet_54100_7585

public string ToggleCase(string input)
{
string result = string.Empty;
char[] inputArray = input.ToCharArray();
foreach (char c in inputArray)
{
if (char.IsLower(c))
result += c.ToString().ToUpper();
else if (char.IsUpper(c))
result += c.ToString().ToLower();
else
result += c.ToString();
}
return result;
}
public string ToggleCase(string input)
{
char[] array = input.ToCharArray();
char temp;
for (int i = ; i < array.Length; i++)
{
temp = array[i];
if (char.IsUpper(temp))
array[i] = char.ToLower(temp);
else if (char.IsLower(temp))
array[i] = char.ToUpper(temp);
}
return new string(array);
}

ASP.NET 对字符串大小写切换的更多相关文章

  1. std::string 字符串大小写转换(转)

    该问题归结为std::transform函数的使用 函数原型 template < class InputIterator, class OutputIterator, class UnaryO ...

  2. Swift3.0语言教程字符串大小写转化

    Swift3.0语言教程字符串大小写转化 Swift3.0语言教程字符串大小写转化,在字符串中,字符串的格式是很重要的,例如首字母大写,全部大写以及全部小写等.当字符串中字符很多时,通过人为一个一个的 ...

  3. 【转】ASP.NET数据库连接字符串总结

    来源:http://blog.csdn.net/lutinghuan/article/details/5973897 ASP.NET数据库连接字符串总结 一.使用OleDbConnection对象连接 ...

  4. [转]ASP.NET数据库连接字符串总结

    这个不难,而且很重要,但总忘,找了篇比较全的,作为资料. 原文链接http://developer.51cto.com/art/201107/275406.htm 关于数据库链接字符串的相关知识,我们 ...

  5. python学习:修改字符串大小写

    修改字符串大小写 函数:title()字符串首字母大写,upper()字符串全部大写,lower()字符串全部小写. 代码举例: name = "ada lovelace"prin ...

  6. linux bash shell:最方便的字符串大小写转换(lowercase/uppercase conversion) (转)

    原文地址:https://blog.csdn.net/10km/article/details/83384145 关于字符串大小写转换,是写 linux 脚本经常干的事儿,所以总想找个方便的方法让我少 ...

  7. mssql sqlserver 判断字符串大小写的方法分享

    摘要:下文讲述使用sql脚本的方法判断字符串为大小写的方法分享,如下所示 实验环境:sqlserver 2008 R2 实现思路: 将字符串转换为大写或小写然后转换为二进制编码, 然后和源字符串做对比 ...

  8. Swift3.0字符串大小写转化

    Swift3.0语言教程字符串大小写转化,在字符串中,字符串的格式是很重要的,例如首字母大写,全部大写以及全部小写等.当字符串中字符很多时,通过人为一个一个的转换是很费时的.在NSString中提供了 ...

  9. 【转】Python 字符串大小写转换

    转载自:python 中字符串大小写转换 一.pyhton字符串的大小写转换, 常用的有以下几种方法: 1.对字符串中所有字符(仅对字母有效)的大小写转换,有两个方法: print 'just to ...

随机推荐

  1. CAShapeLayer的path动画

    CAShapeLayer的path动画 效果 源码 https://github.com/YouXianMing/Animations // // CAShapeLayerPathController ...

  2. [翻译] AnimatedPath 动画路径(持续更新)

    AnimatedPath动画路径 感谢原作者分享精神,有空补上使用教程 https://github.com/twotoasters/AnimatedPath AnimatedPath explore ...

  3. 基于Android的ELF PLT/GOT符号重定向过程及ELF Hook实现(by 低端码农 2014.10.27)

    引言 写这篇技术文的原因,主要有两个: 其一是发现网上大部分描写叙述PLT/GOT符号重定向过程的文章都是针对x86的.比方<Redirecting functions in shared EL ...

  4. C#调用DLL各种传参

    C++#define JNAAPI extern "C" __declspec(dllexport) // C方式导出函数 typedef struct { int osVersi ...

  5. 设置IE浏览器指定的功能

    if ($.browser.msie) { // Internet Explorer is a sadist. }

  6. 分布式缓存系统Memcached在Asp.net下的应用

    Memcached 是一个高性能的分布式内存对象缓存系统.用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来降低读取数据库的次数,从而提高动态.数据库驱动站点的速度. Memcache ...

  7. OTL翻译(1) -- 说明

    说明 该文档说明的是4.0版本的ORACLE/ODBC和DB2-CLI模板库(OTL).OTL4.0(后面简称OTL)模板库是基于C++的模板的. OTL4.0是组合了C++的模板框架和OTL适配器. ...

  8. c++ placement new概念

    参考:http://www.cnblogs.com/Clingingboy/archive/2013/04/26/3044910.html 转:http://bbs.chinaunix.net/thr ...

  9. Android制作曲线、柱状图、饼形等图表——使用AChartEngine

    之前在java开发中实现图表使用JFreeChar组件,最近有个小项目要求在Android端进行数据分析,如何实现图表呢?查了一下google提供了一个开源组件Achartengine非常好用,可实现 ...

  10. chrome的护眼插件