Capitalization of string

To convert string to title case (capitalize initial letters of the string), there is not string method to call. However, we can use the CultureInfo from Globalization and use the TextInfo’s ToTitleCase method.
Here is how it can be done in C#:

Add class StringExtensions to your root namespace and copy the code,All string variables in your project will now shows ToTitleCase method (extension method)

public static class StringExtensions
    public static string ToTitleCase(this string input)
        System.Globalization.CultureInfo cultureInfo =
        System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
        return textInfo.ToTitleCase(input.ToLower());

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s