How to make a first letter capital in C#

后端 未结 12 1194
攒了一身酷
攒了一身酷 2020-12-05 23:52

How can the first letter in a text be set to capital?

Example:

it is a text.  = It is a text.
12条回答
  •  甜味超标
    2020-12-05 23:57

    this functions makes capital the first letter of all words in a string

    public static string FormatSentence(string source)
        {
            var words = source.Split(' ').Select(t => t.ToCharArray()).ToList();
            words.ForEach(t =>
            {
                for (int i = 0; i < t.Length; i++)
                {
                    t[i] = i.Equals(0) ? char.ToUpper(t[i]) : char.ToLower(t[i]);
                }
            });
            return string.Join(" ", words.Select(t => new string(t)));;
        }
    

提交回复
热议问题