Jaden的推特

来源:互联网 发布:java调用restful api 编辑:程序博客网 时间:2024/04/30 09:48

描述:

将一个英文字符串里的所有首字母大写

例如:

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);    }}
0 0
原创粉丝点击