如何在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
热门推荐
10 毕业教师花语祝福语简短
11 学校校长新年祝福语简短
12 爸妈金婚文案祝福语简短
13 弟弟考上军校祝福语简短
14 写春节祝福语简短的
15 朋友买新房祝福语简短
16 新郎朋友祝福语简短大气
17 谢谢学校老师祝福语简短
18 物业小区高考祝福语简短