Converting a Given String to Title Case

To convert a string in the title case is a bit tedious and may require lots of code. And as per my knowledge there is no direct method available in C#.Net in String class for this purpose. So, here I am sharing a method, which will be the extension method for the String class and can be used to convert a given string to the title case.

Here, I am using the CultureInfo from the Globalization and the ToTitleCase method of the TextInfoclass.

public static class StringExtensions

{

    public static string ConvertToTitleCase(this string input)

    {

        System.Globalization.CultureInfo cultureInfo =

        System.Threading.Thread.CurrentThread.CurrentCulture;

        System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;

        return textInfo.ToTitleCase(input.ToLower());

    }

}

Hope reusing this will save you lots of time :)