Select the product you need help with
How to convert strings to lower, upper, or title (proper) case by using Visual C#Article ID: 312890 - View products that this article applies to. This article was previously published under Q312890 On This PageSUMMARY
This article demonstrates how to convert a string to uppercase, lowercase, or title (or proper) case. Although you can use methods of the String class to convert a string to uppercase or lowercase, you must use a method in the TextInfo class of the System.Globalization namespace to convert a string to title case. The String class does not include a built-in method to convert a string to title case. Convert String Using the String ClassThis section describes how to use the methods of the String class to convert a string to uppercase and lowercase.Convert a String to UppercaseThe String class has a static method named ToUpper. You can use this method to convert a string to uppercase. For example:Convert a String to LowercaseThe ToLower method is the complement of the ToUpper method. ToLower converts a string to lowercase. For example:Convert String Using the TextInfo ClassThis section describes how to use the TextInfo class to convert a string to title case.Convert a String to Title CaseThe String class does not include a method that converts a string to title case. The ToTitleCase method resides in the TextInfo class, which is a member of the System.Globalization namespace. Unlike the ToUpper and ToLower methods of the String class, the ToTitleCase method is not a static method and requires an instance of the class.When you use the TextInfo class, you must specify cultural information. In most situations, you can default to the culture that is currently in use. Culture information is a property of the thread on which the code is running. To obtain the culture information, you must gain access to the current thread and retrieve the CurrentCulture property from that thread. Once you accomplish this, you can create the TextInfo object. For example: Step-by-Step Example
Note on the InvariantCulture PropertyWhen you use the Globalization namespace to convert data, if you store the converted data instead of displaying it for the user, you may want to use the InvariantCulture property of CultureInfo class.InvariantCulture is neither a neutral nor a specific culture; it is a culture that is culture-insensitive. If you use InvariantCulture when you store data, the data is stored in a consistent manner, regardless of any specific user or cultural system settings that may be in effect. For more information, refer to the References section. The preceding code sample uses the CultureInfo properties of the current thread: REFERENCES
For additional information, see to the following topics in the Microsoft Visual Studio Online Help documentation:
Properties | Article Translations
|


Back to the top








