Convert first character to upper. - CSharp System

CSharp examples for System:String Convert

Description

Convert first character to upper.

Demo Code


using System;/*ww w  .  j  a v a 2s  . c o m*/

public class Main{
        /// <summary>
        /// Convert first character to upper.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string FirstCharacterToUpper(this string str)
        {
            if (String.IsNullOrEmpty(str) || Char.IsUpper(str, 0))
            {
                return str;
            }

            return Char.ToUpperInvariant(str[0]) + str.Substring(1);
        }
}

Related Tutorials