如何在C#中将字符串转换为标题大小写?
标题大小写是主要标题的首字母大写的任何文本,例如标题或标题。标题大小写或标题大小写是一种大写形式,用于以英语呈现已发表的作品或艺术品的标题。使用标题大小写时,除“次要”单词外,所有单词均大写,除非它们是单词的首字母或尾字母。标题。
示例中ToTitleCase的当前实现产生的输出字符串的长度与输入字符串的长度相同。
例子1
class Program{
static void Main(string[] args){
string myString = "wAr aNd pEaCe";
TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
Console.WriteLine("\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase(myString));
Console.ReadLine();
}
}输出结果
"war and peace" to titlecase: War And Peace
例子2
class Program{
static void Main(string[] args){
string[] values = {
"a tale of three cities", "gROWL rescue",
"inside the office", "sports and tennis",
"The Return of Christmas Holmes"
};
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
foreach (var value in values)
Console.WriteLine("{0} −−> {1}", value, ti.ToTitleCase(value));
Console.ReadLine();
}
}输出结果
a tale of three cities −−> A Tale Of Three Cities gROWL rescue −−> Growl Rescue inside the office −−> Inside The Office sports and tennis −−> Sports And Tennis The Return of Christmas Holmes −−> The Return Of Christmas Holmes
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短