String Title Case

The String Class in C# is a sealed class, which means that it cannot be used as a base class for creating derived classes. In other words, you cannot inherit another class from the String class.

ToTitleCase

One of the useful methods provided by the String class is ToTitleCase. This method is designed to convert the first character of each word in a string to uppercase, while converting all other characters to lowercase. This can be particularly helpful when you want to ensure consistent capitalization for titles or headings.

System.Globalization.CultureInfo cultureInfo = _ new System.Globalization.CultureInfo("en-US");

When working with cultures and internationalization, a neutral culture is often specified using a two-letter lowercase language code. For example, "fr" represents the neutral culture for French, while "de" represents the neutral culture for German. By specifying a neutral culture, you can access language-specific information and behaviors.The following C# source code shows how to convert a string to Title Case.

Full Source C#
using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string _str = null; System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US"); _str = cultureInfo.TextInfo.ToTitleCase("make first letter capital"); MessageBox.Show (_str); } } }

Conclusion

To handle culture-specific operations and retrieve relevant information, C# provides the CultureInfo class. This class enables you to access various details associated with a specific culture, such as the language, sublanguage, country/region, calendar system, and cultural conventions. It serves as a valuable resource for performing culture-specific operations and adapting your application to different linguistic and regional requirements.