String extension method which capitalizes the first letter of the input string. - CSharp System

CSharp examples for System:String Case

Description

String extension method which capitalizes the first letter of the input string.

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;//from   w  w w  . j  a va2 s .c  om

public class Main{
        /// <summary>
        /// String extension method which capitalizes the first letter of the input string. 
        /// </summary>
        /// <param name="input">The string on which the method is invoked.</param>
        /// <returns>Returns the input string with capital first letter.</returns>
        public static string CapitalizeFirstLetter(this string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }

            return input.Substring(0, 1).ToUpper(CultureInfo.CurrentCulture) + input.Substring(1, input.Length - 1);
        }
}

Related Tutorials