C#中字符,字符串的大小写转换
来源:互联网 发布:晾霸 好太太 知乎 编辑:程序博客网 时间:2024/05/20 15:40
字符串
对字符串来说,"string".ToLower()和"string".ToUpper()可以基本满足需求,但是当需要将首字母大写的时候,这两个函数就有点不够用了.但还好,我们还有TextInfo类下的ToLittleCase方法.在使用TextInfo类时,必须指定区域性.要获得区域性,必须能够访问当前线程,从该线程中检索CurrentCulture属性.
using System;using System.Globalization;using System.Threading;namespace csConsole{ public class MyClass { public static void Main() { string title="this is my converted string"; Console.WriteLine("String Class"); Console.WriteLine("------------"); //Convert string to uppercase. Console.WriteLine(title.ToUpper()); //Convert string to lowercase. Console.WriteLine(title.ToLower()); Console.WriteLine(); Console.WriteLine("TextInfo Class"); Console.WriteLine("--------------"); //Get the culture property of the thread. CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; //Create TextInfo object. TextInfo textInfo = cultureInfo.TextInfo; //Convert to uppercase. Console.WriteLine(textInfo.ToUpper(title)); //Convert to lowercase. Console.WriteLine(textInfo.ToLower(title)); //Convert to title case. Console.WriteLine(textInfo.ToTitleCase(title));} }}
字符
对字符来说,最初将一个字符变为小写,我是这样做的 char itemLower = Convert.ToChar(item.ToString().ToLower()) ,很傻很天真的方法.后来,我才查到char有静态方法ToUpper,ToLowwer,所以可以这样做.
char itemLower = char.ToLower(item); char itemUpper = char.ToUpper(item);
0 0
- C#中字符,字符串的大小写转换
- 字符串中大小写的转换
- C++ 字符、字符串大小写的转换
- C++ 中字符大小写转换的函数
- string类中字符的大小写转换
- 字符的大小写转换
- 字符的大小写转换!
- 字符大小写的转换
- 大小写字符的转换
- 判断指定字符在字符串中出现的次数,并且转换大小写(作业)
- java字符串中提取相应位置的字符及大小写转换
- java中一个字符串的大小写转换
- Java中字符串的大小写转换
- 字符串的大小写转换
- C#中字符串的ASCII码转换为字符
- C#之字符判断和大小写的转换
- PHP中字符串大小写转换
- C#入门6.3——字符串的大小写转换
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。
- Codeforces Round #FF (Div. 2)C.DYZ Loves Sequence
- 如何学习C语言最有效
- How to Keep Thread-Safe When Queuing Your Data
- 织梦DedeCMS自带采集规则只能够选择文章和图集模型的修改
- C#中字符,字符串的大小写转换
- 按照时间戳中的day 聚合排序
- 【健康生活】优秀程序员必备的15大技能
- Tomcat UTF-8 编码设置
- ubuntu 周期性任务管理 --crontab
- Python django web training——(三)我的第一个blog
- POJ2632
- The function that returns the pointer (C Programming)
- 一个奋斗十年的程序员从无到有买系5