{"id":68251,"date":"2022-04-02T08:58:23","date_gmt":"2022-04-02T06:58:23","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=68082"},"modified":"2023-04-25T10:01:44","modified_gmt":"2023-04-25T08:01:44","slug":"csharp-convert-string-title-case","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/","title":{"rendered":"How to Convert String to Title Case in C#"},"content":{"rendered":"<p>In this article, we are going to learn how to convert string to title case in C#. In the title case, the first character of a word is the uppercase letter, while the remaining characters are in lowercase.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/strings-csharp\/StringToTitleCase\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s dive in.<\/p>\n<h2>Using ToTitleCase Method to Convert String to Title Case in C#<\/h2>\n<p>C# has an inbuilt <code>TextInfo.ToTitleCase()<\/code> method that we can use to convert strings to title case:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string ToTitleCase (string str);<\/code><\/p>\n<p>This method exists within <code>System.Globalization<\/code> namespace. However, <code>TextInfo.ToTitleCase()<\/code> cannot convert words that are entirely in uppercase to title case. We will see how to do that later on.<\/p>\n<p>To use the <code>ToTitleCase()<\/code> method, we first need to create a <code>TextInfo<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var textinfo = new CultureInfo(\"en-US\", false).TextInfo;<\/code><\/p>\n<p>As you can see, we create a <code>TextInfo<\/code> based on the &#8220;en-US&#8221; culture. We can also use the culture of our current location when declaring the <code>TextInfo<\/code> instance:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var textinfo = CultureInfo.CurrentCulture.TextInfo;<\/code><\/p>\n<p>Afterward, we can call <code>ToTitleCase()<\/code> and convert our desired string to a title case:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine(textinfo.ToTitleCase(\"a tale oF tWo citIes\"));\r\n\r\nConsole.WriteLine(textinfo.ToTitleCase(\"harry potter and the Deathly hallows\"));<\/pre>\n<h3>Converting an Entire Uppercase String to Title Case<\/h3>\n<p>As we said earlier, <code>ToTitleCase()<\/code> cannot convert words that are entirely uppercase such as acronyms. To convert such words, we have to parse the string as lowercase:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine(textinfo.ToTitleCase(\"OLIVER TWIST\".ToLower()));<\/code><\/p>\n<p>Furthermore, it is worth mentioning that <code>ToTitleCase<\/code> method is not linguistically correct. Compared to our previous examples, the linguistically correct outcome would be:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">A Tale of Two Cities\r\n\r\nHarry Potter and the Deathly Hallows<\/pre>\n<p>Nonetheless, <code>ToTitleCase()<\/code> is a simpler and faster way of converting strings to title cases.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we have learned how we can convert strings to title cases in C# using the <code>TextInfo.ToTitleCase()<\/code> method. We&#8217;ve also learned how to convert the all-uppercase strings to title-case strings.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn how to convert string to title case in C#. In the title case, the first character of a word is the uppercase letter, while the remaining characters are in lowercase. Let&#8217;s dive in. Using ToTitleCase Method to Convert String to Title Case in C# C# has an [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[1192,242,1193],"class_list":["post-68251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-convert-string-to-title-case","tag-string","tag-titlecase","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Convert String to Title Case in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to learn how to convert string to title case in C# with different examples that will help us in a process.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Convert String to Title Case in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to learn how to convert string to title case in C# with different examples that will help us in a process.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-02T06:58:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-25T08:01:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"How to Convert String to Title Case in C#\",\"datePublished\":\"2022-04-02T06:58:23+00:00\",\"dateModified\":\"2023-04-25T08:01:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\"},\"wordCount\":272,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"Convert string to title case\",\"String\",\"TitleCase\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\",\"url\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\",\"name\":\"How to Convert String to Title Case in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-04-02T06:58:23+00:00\",\"dateModified\":\"2023-04-25T08:01:44+00:00\",\"description\":\"In this article, we are going to learn how to convert string to title case in C# with different examples that will help us in a process.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Convert String to Title Case in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Convert String to Title Case in C# - Code Maze","description":"In this article, we are going to learn how to convert string to title case in C# with different examples that will help us in a process.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/","og_locale":"en_US","og_type":"article","og_title":"How to Convert String to Title Case in C# - Code Maze","og_description":"In this article, we are going to learn how to convert string to title case in C# with different examples that will help us in a process.","og_url":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/","og_site_name":"Code Maze","article_published_time":"2022-04-02T06:58:23+00:00","article_modified_time":"2023-04-25T08:01:44+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"How to Convert String to Title Case in C#","datePublished":"2022-04-02T06:58:23+00:00","dateModified":"2023-04-25T08:01:44+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/"},"wordCount":272,"commentCount":5,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["Convert string to title case","String","TitleCase"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-convert-string-title-case\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/","url":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/","name":"How to Convert String to Title Case in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-04-02T06:58:23+00:00","dateModified":"2023-04-25T08:01:44+00:00","description":"In this article, we are going to learn how to convert string to title case in C# with different examples that will help us in a process.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-convert-string-title-case\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-convert-string-title-case\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"How to Convert String to Title Case in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/68251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=68251"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/68251\/revisions"}],"predecessor-version":[{"id":87557,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/68251\/revisions\/87557"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=68251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=68251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=68251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}