{"id":1002,"date":"2023-03-14T11:28:08","date_gmt":"2023-03-14T11:28:08","guid":{"rendered":"https:\/\/www.naveedulhaq.com\/?p=1002"},"modified":"2023-03-16T18:56:03","modified_gmt":"2023-03-16T18:56:03","slug":"format-strings-in-csharp","status":"publish","type":"post","link":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/","title":{"rendered":"How to Format Strings in C#"},"content":{"rendered":"\n<p>In C#, string formatting is like combining different things such as strings, values, and expressions to create a cool formatted string. It&#8217;s like setting up a template with placeholders that will be replaced with actual values when your code runs.<\/p>\n\n\n\n<p>Why is this so important? Well, it helps make your output more readable and easier to understand. You can mix text and values in a way that makes sense to whoever&#8217;s reading it. Plus, it&#8217;s a handy way to tackle tricky formatting situations without too much hassle.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C# String Format<\/h2>\n\n\n\n<p>Now, when I started out learning to code, then formatting String was something that confused me a lot. Therefore, this post offers possible methods to format a string in C#.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method 1: Using the String Interpolation<\/h2>\n\n\n\n<p>Hey, did you know that you can format your strings in C# using variables and placeholders? It&#8217;s called String Interpolation and it&#8217;s pretty cool! All you have to do is use these placeholders and then replace them with their respective values. This process is known as string interpolation, and it&#8217;s a great way to make your code look neat and tidy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Syntax:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string str = $\"Welcome to {var1}, Naveed-Ul-Haq's Blog {var2}\";<\/code><\/pre>\n\n\n\n<p>You can clearly see the working through the syntax, like, you need to put \u201c<strong>$<\/strong>\u201d before the string starts. After that, you need to start the string and put the variable names in the braces as shown.<\/p>\n\n\n\n<p>Want more understanding? Let\u2019s practice it through the example:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example:<\/strong><\/h3>\n\n\n\n<p>This example presents the application of the format specifiers in the string where two substrings are being used in the string:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string niche = \"C#, .NET, Azure, etc\";<br>string topic = \"Format String in C#\";<br>string res = string res = $\"You are at Naveed's Blog, which offers tutorials on {niche}, \\nand today's post is about {topic}\";<br>Console.WriteLine(res);<\/code><\/pre>\n\n\n\n<p>Here, two variables are initialized \u201c<strong>niche<\/strong>\u201d and \u201c<strong>topic<\/strong>\u201d which are used furtherly in the string \u201c<strong>res<\/strong>\u201d. Let\u2019s see the output:<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"973\" height=\"213\" src=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/1.png\" loading=\"lazy\" alt=\"\" class=\"wp-image-1004\" srcset=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/1.png 973w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/1-300x66.png 300w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/1-768x168.png 768w\" sizes=\"auto, (max-width: 973px) 100vw, 973px\" \/><\/figure>\n\n\n\n<p>Here, the placeholders have been added and the string is formatted for better readability.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method 2: Using Format() Method<\/strong><\/h2>\n\n\n\n<p>Check it out, there&#8217;s a method in C# that lets you combine values of variables with a format string to make a fancy formatted string! The placeholders for the variables are marked with braces ({}) and you can even specify which variable goes where by using its index or name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Syntax:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string res = String.Format(\"Welcome {0}, to Naveed\u2019s Blog {1}\", var1, var2);<\/code><\/pre>\n\n\n\n<p>Here, the syntax seems to be the same as above. The variables are called inside the string with the \u201c<strong>index<\/strong>\u201d number in the braces \u201c<strong>{}<\/strong>\u201d and the <strong>var1<\/strong>, and <strong>var2 <\/strong>refer to the variable names.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 1:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string var1= \"Naveed Ul Haq\";<br>String blog = \"naveedulhaq.com\"<br>string res = String.Format(\"Hello, I am {0}, and I blogs at {1}\", var1, var2);<br>Console.WriteLine(res);<\/code><\/pre>\n\n\n\n<p>Now, there are two variables \u201c<strong>var1<\/strong>\u201d and \u201c<strong>var2<\/strong>\u201d, these are called in the string using their index numbers, i.e, <strong>var1 <\/strong>and <strong>var2 <\/strong>refer to the {<strong>0<\/strong>} and {<strong>1<\/strong>} \u201cgeneral format specifier to call a variable\u201d.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1057\" height=\"188\" src=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/2-1024x182.png\" loading=\"lazy\" alt=\"C# String Format\" class=\"wp-image-1005\" srcset=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/2-1024x182.png 1024w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/2-300x53.png 300w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/2-768x137.png 768w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/2.png 1057w\" sizes=\"auto, (max-width: 1057px) 100vw, 1057px\" \/><figcaption class=\"wp-element-caption\">C# String Format<\/figcaption><\/figure>\n\n\n\n<p>Look at the output, the general format specifiers have been replaced with the value of the variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 2: Format the Decimal<\/strong><\/h3>\n\n\n\n<p>The decimal numbers sometimes have a very long number after the float time. The decimal point can be restricted to a specific decimal point:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Code:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>double num = 0.123;<br>string str = string.Format(\"The Number is: {0:F2}\", num);<br>Console.WriteLine(str);<\/code><\/pre>\n\n\n\n<p>This will get the current date and time and show it on the provided syntax:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"157\" src=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/3.png\" loading=\"lazy\" alt=\"C# String Format\" class=\"wp-image-1006\" srcset=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/3.png 759w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/3-300x62.png 300w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><figcaption class=\"wp-element-caption\">C# String Format<\/figcaption><\/figure>\n\n\n\n<p>The number has been restricted to 2 decimal places.<\/p>\n\n\n\n<p><strong>Note: <\/strong>The core functionality of the string format depends on the format specifiers. Navigate to Microsoft\u2019s official documentation to get the supported format specifiers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Method 3: Using String Concatenation<\/strong><\/h3>\n\n\n\n<p>String concatenation also helps in getting the formatted string. Just you need to add the \u201c<strong>+<\/strong>\u201d sign to add the variable with the string:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Code:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int a=10;<br>string b = \" Tens of tutorials on\";<br>string str = String.Format(\"Welcome to N-UL-HAQ\" + b + \" C#\/.NET\/Azure\" + a);<br>Console.WriteLine(str);<\/code><\/pre>\n\n\n\n<p>The above code has two variables one is a string and the other is an integer. These are concatenated with the \u201cstr\u201d variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"887\" height=\"161\" src=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/4.png\" loading=\"lazy\" alt=\"C# String Format\" class=\"wp-image-1007\" srcset=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/4.png 887w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/4-300x54.png 300w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/03\/4-768x139.png 768w\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" \/><figcaption class=\"wp-element-caption\">C# String Format<\/figcaption><\/figure>\n\n\n\n<p>The output shows that both variables are concatenated and the string is formatted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wrap Up<\/strong><\/h2>\n\n\n\n<p>So, Format String is basically a way to get a nicely formatted version of a string for easy reading and consistent output. In C#, which is pretty advanced, there are a bunch of methods you can use to format strings, like the Format() method and string interpolation. You use these methods together with format specifiers to get the result you want.<\/p>\n\n\n\n<p>This post has listed all these methods to format a string in C#. <\/p>\n\n\n\n<p>If you want to learn the C# switch statement visit my blog on <a href=\"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/switch-statement-in-c-explained\/\">C# switch<\/a>. Get in touch with this Blog to stay updated with the <a href=\"https:\/\/www.naveedulhaq.com\/index.php\/category\/dot-net-core\/\">tutorials on C#<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C#, string formatting is like combining different things such as strings, values, and expressions to create a cool formatted string. It&#8217;s like setting up&#8230;<\/p>\n","protected":false},"author":3,"featured_media":641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[11,8,62,37,32,56],"class_list":["post-1002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net-core","tag-dot-net-core","tag-dot-net-framework","tag-asp-net","tag-c","tag-developer","tag-visual-studio"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Format Strings in C# - Naveed Ul-Haq&#039;s blog<\/title>\n<meta name=\"description\" content=\"There are various methods that can be used to format strings in C#. Read this detailed guide to learn more! - Naveed Ul-Haq&#039;s blog\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Format Strings in C# - Naveed Ul-Haq&#039;s blog\" \/>\n<meta property=\"og:description\" content=\"There are various methods that can be used to format strings in C#. Read this detailed guide to learn more! - Naveed Ul-Haq&#039;s blog\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/\" \/>\n<meta property=\"og:site_name\" content=\"Naveed Ul-Haq&#039;s blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-14T11:28:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-16T18:56:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png\" \/>\n\t<meta property=\"og:image:width\" content=\"240\" \/>\n\t<meta property=\"og:image:height\" content=\"240\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abdul Mannan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abdul Mannan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/\"},\"author\":{\"name\":\"Abdul Mannan\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/8babf3cd198e47e5c727f67880ea7977\"},\"headline\":\"How to Format Strings in C#\",\"datePublished\":\"2023-03-14T11:28:08+00:00\",\"dateModified\":\"2023-03-16T18:56:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/\"},\"wordCount\":702,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/dd6db5980b965fcae41e096d357c65c9\"},\"image\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"keywords\":[\".net core\",\".net framework\",\"asp.net\",\"c#\",\"developer\",\"visual-studio\"],\"articleSection\":[\".NET\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/\",\"url\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/\",\"name\":\"How to Format Strings in C# - Naveed Ul-Haq&#039;s blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"datePublished\":\"2023-03-14T11:28:08+00:00\",\"dateModified\":\"2023-03-16T18:56:03+00:00\",\"description\":\"There are various methods that can be used to format strings in C#. Read this detailed guide to learn more! - Naveed Ul-Haq&#039;s blog\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"contentUrl\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"width\":240,\"height\":240,\"caption\":\".net\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/format-strings-in-csharp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.naveedulhaq.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Format Strings in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#website\",\"url\":\"https:\\\/\\\/www.naveedulhaq.com\\\/\",\"name\":\"Naveed Ul-Haq's blog\",\"description\":\"AI, Optimizely, Azure &amp; more\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/dd6db5980b965fcae41e096d357c65c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.naveedulhaq.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/dd6db5980b965fcae41e096d357c65c9\",\"name\":\"Naveed Ul-Haq\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\",\"caption\":\"Naveed Ul-Haq\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\"},\"description\":\"I lead engineering delivery teams for digital commerce and digital experience platforms, combining hands-on architecture experience with strong delivery governance. Over 20+ years, I\u2019ve built and led cross\u2011functional teams (engineering, BA, QA) delivering modern cloud solutions on Azure, microservices, APIs and eCommerce\\\/CMS platforms. My recent focus includes AI-enabled commerce automation: product ingestion and enrichment workflows, content optimisation for SEO and shopping feeds, and agentic tooling to improve marketing and accessibility workflows. I\u2019m passionate about building high-performing teams, establishing quality\\\/release standards, and delivering measurable outcomes across performance, reliability, and speed of change.\",\"sameAs\":[\"https:\\\/\\\/www.naveedulhaq.com\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedulhaq\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/8babf3cd198e47e5c727f67880ea7977\",\"name\":\"Abdul Mannan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g\",\"caption\":\"Abdul Mannan\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Format Strings in C# - Naveed Ul-Haq&#039;s blog","description":"There are various methods that can be used to format strings in C#. Read this detailed guide to learn more! - Naveed Ul-Haq&#039;s blog","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:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/","og_locale":"en_GB","og_type":"article","og_title":"How to Format Strings in C# - Naveed Ul-Haq&#039;s blog","og_description":"There are various methods that can be used to format strings in C#. Read this detailed guide to learn more! - Naveed Ul-Haq&#039;s blog","og_url":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/","og_site_name":"Naveed Ul-Haq&#039;s blog","article_published_time":"2023-03-14T11:28:08+00:00","article_modified_time":"2023-03-16T18:56:03+00:00","og_image":[{"width":240,"height":240,"url":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","type":"image\/png"}],"author":"Abdul Mannan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Abdul Mannan","Estimated reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#article","isPartOf":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/"},"author":{"name":"Abdul Mannan","@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/8babf3cd198e47e5c727f67880ea7977"},"headline":"How to Format Strings in C#","datePublished":"2023-03-14T11:28:08+00:00","dateModified":"2023-03-16T18:56:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/"},"wordCount":702,"commentCount":0,"publisher":{"@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/dd6db5980b965fcae41e096d357c65c9"},"image":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","keywords":[".net core",".net framework","asp.net","c#","developer","visual-studio"],"articleSection":[".NET"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/","url":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/","name":"How to Format Strings in C# - Naveed Ul-Haq&#039;s blog","isPartOf":{"@id":"https:\/\/www.naveedulhaq.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#primaryimage"},"image":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","datePublished":"2023-03-14T11:28:08+00:00","dateModified":"2023-03-16T18:56:03+00:00","description":"There are various methods that can be used to format strings in C#. Read this detailed guide to learn more! - Naveed Ul-Haq&#039;s blog","breadcrumb":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#primaryimage","url":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","contentUrl":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","width":240,"height":240,"caption":".net"},{"@type":"BreadcrumbList","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/format-strings-in-csharp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.naveedulhaq.com\/"},{"@type":"ListItem","position":2,"name":"How to Format Strings in C#"}]},{"@type":"WebSite","@id":"https:\/\/www.naveedulhaq.com\/#website","url":"https:\/\/www.naveedulhaq.com\/","name":"Naveed Ul-Haq's blog","description":"AI, Optimizely, Azure &amp; more","publisher":{"@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/dd6db5980b965fcae41e096d357c65c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.naveedulhaq.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/dd6db5980b965fcae41e096d357c65c9","name":"Naveed Ul-Haq","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g","caption":"Naveed Ul-Haq"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g"},"description":"I lead engineering delivery teams for digital commerce and digital experience platforms, combining hands-on architecture experience with strong delivery governance. Over 20+ years, I\u2019ve built and led cross\u2011functional teams (engineering, BA, QA) delivering modern cloud solutions on Azure, microservices, APIs and eCommerce\/CMS platforms. My recent focus includes AI-enabled commerce automation: product ingestion and enrichment workflows, content optimisation for SEO and shopping feeds, and agentic tooling to improve marketing and accessibility workflows. I\u2019m passionate about building high-performing teams, establishing quality\/release standards, and delivering measurable outcomes across performance, reliability, and speed of change.","sameAs":["https:\/\/www.naveedulhaq.com","https:\/\/www.linkedin.com\/in\/naveedulhaq\/"]},{"@type":"Person","@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/8babf3cd198e47e5c727f67880ea7977","name":"Abdul Mannan","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g","caption":"Abdul Mannan"}}]}},"_links":{"self":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/posts\/1002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/comments?post=1002"}],"version-history":[{"count":0,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/posts\/1002\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/media\/641"}],"wp:attachment":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/media?parent=1002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/categories?post=1002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/tags?post=1002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}