How to make a first letter capital in C#

后端 未结 12 1190
攒了一身酷
攒了一身酷 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:55

    public static string ToUpperFirstLetter(this string source)
    {
        if (string.IsNullOrEmpty(source))
            return string.Empty;
        // convert to char array of the string
        char[] letters = source.ToCharArray();
        // upper case the first char
        letters[0] = char.ToUpper(letters[0]);
        // return the array made of the new char array
        return new string(letters);
    }
    

提交回复
热议问题