Banner Ad

Monday, September 15, 2014

ASP.Net Forums - FAQ #5: How to change the Title Case of a string to Uppercase in Server Side?

By Francis   Posted at   12:04 PM   ASP.Net Forums No comments
One of the user in the forum asked similar to this question. In server side, I thought take the string, and covert it to character array and loop thru the character and change the first Letter alone to capital letter.
                     Instead,we can use “TextInfo” class to achieve the solution in a easier manner. The below function used to convert the given string’s first character alone as a Capital letter.

       
        using System.Globalization;
        using System.Threading;
        public string changeName(string inputname)
        {
            string modifiedname = string.Empty;
            string[] names = inputname.Split(' ');
            foreach (string name in names)
            {
                    CultureInfo cultureInfo   = Thread.CurrentThread.CurrentCulture;
                    TextInfo txtinfo = cultureInfo.TextInfo;
                    string temp=txtinfo.ToTitleCase(name);
                    modifiedname = string.Concat(temp, " ");
            }
            return modifiedname;
        }

About Francis

Francis, an Associate at Cognizant. Having 7+ Years of experience in Microsoft web technologies.

0 comments :

Please give your valuable comments to improve the contents

Connect with Us