Required output. Consider a simple string in C# like "purple fish." The string has 2 words separated with a space. Each word should have an uppercase letter.
Required input, output:
purple fish -> Purple Fish
Example. This program shows how to call ToTitleCase. To access CultureInfo, you need to include the System.Globalization namespace. The input here is "purple fish."
And The output is "Purple Fish." The first letters of the 2 words are converted to uppercase.
C# program that uses ToTitleCase
static void Main()
string value = "purple fish";
string titleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value);
A discussion. When should ToTitleCase be used? Programs often have edge cases. A custom implementation can provide better support for certain words.
And Performance can be improved in custom algorithms. When performance is critical, caching with memoization could help.