Capitalizes the first letter of the String in the StringBuilder object - CSharp System

CSharp examples for System:String Case

Description

Capitalizes the first letter of the String in the StringBuilder object

Demo Code


using System.Text;
using System;//from w  w w  . j  av  a2s.co  m

public class Main{
        /// <summary>
        /// Capitalizes the first letter of the String in the StringBuilder object
        /// </summary>
        /// <param name="sb">StringBuilder object</param>
        /// <returns>Returns a new stringbuilder object</returns>
        public static StringBuilder CapitalizeFirst(this StringBuilder sb)
        {
            Validation.IsNotNull(sb, "sb");
            Validation.Validate(sb.Length > 0);

            return sb.Replace(sb[0], char.ToUpper(sb[0]), 0, 1);
        }
}

Related Tutorials