Convert string into Title Case in C#


Convert string into Title Case in C#  by Extension method

1.      using TextInfo class. 


public static class StringExtension
    {
        /// <summary>
        /// Use to convert string into Title Case
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ToTitleCase(this string str)
        {
            if (!String.IsNullOrEmpty(str))
                return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(str.ToLower());

            return null;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string str = "convert STRING into titlecase in c#"
            Console.WriteLine( str.ToTitleCase());
            Console.ReadLine();
        }

    }


Comments

Popular posts from this blog

iframe vs embed vs object in HTML 5

Constructor in c#

What is the need of method overriding ???