Capitalize the first letter of a string - CSharp System

CSharp examples for System:String Case

Description

Capitalize the first letter of a string

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System;/*from  w w w. j a v a 2 s.  c om*/

public class Main{
        /// <summary>
        /// Capitalize the first letter of a string
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string Capitalize(string value)
        {
            if (String.IsNullOrWhiteSpace(value))
                return value;
            return String.Format(CultureInfo.CurrentCulture, "{0}{1}", value[0].ToString().ToUpper(CultureInfo.CurrentCulture), value.Substring(1, value.Length - 1));
        }
}

Related Tutorials