描述:
将一个英文字符串里的所有首字母大写
例如:
Not Jaden-Cased: “How can mirrors be real if our eyes aren’t real”
Jaden-Cased: “How Can Mirrors Be Real If Our Eyes Aren’t Real”
CodeWar:
using System;
using System.Linq;
public static class JadenCase
{
public static string ToJadenCase(this string phrase)
{
char[] a = phrase.ToLower().ToCharArray();//将输入的字符串转为小写的单字符数组
for (int i = 0; i < a.Count(); i++ )
{
//用char.ToUpper将第一位和前一位为“ ”的字符大写
a[i] = i == 0 || a[i-1] == ' ' ? char.ToUpper(a[i]) : a[i];
}
return new string(a);//转为字符串并返回
}
}
using System.Globalization;
public static class JadenCase
{
public static string ToJadenCase(this string phrase)
{
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(phrase);
}
}