TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# ToTitleCase Method

Use the ToTitleCase method from System.Globalization and understand the drawbacks of this method.
ToTitleCase makes each word title case. It capitalizes each word in a string. You could develop character-based algorithms to accomplish this goal. But the System.Globalization namespace provides ToTitleCase, which can be simpler.TextInfo
Example. This program shows how to call ToTitleCase and the string value it returns. To access CultureInfo, you need to include the System.Globalization namespace. The input to the program is "dot net Codex".

And: The output is "The Dev Codes". The d, n, and p are converted to uppercase.

C# program that uses ToTitleCase using System; using System.Globalization; class Program { static void Main() { string value = "dot net Codex"; string titleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value); Console.WriteLine(titleCase); } } Output The Dev Codes
Discussion. When should ToTitleCase be used? And when should a custom implementation 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.Uppercase First Letter

Note: This method was suggested by Atoki as an alternative to the more elaborate implementations.

Summary. We looked at the ToTitleCase method on the TextInfo type. There are other methods available on TextInfo. They are detailed in a separate article. ToTitleCase can simplify your program, but it cannot be easily customized.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf