This article illustrates the different techniques to capitalize the first letter of each word in a string in C#.

1. Using TextInfo.ToTitleCase() method

To convert a string to a title case, you can use the TextInfo.ToTitleCase() method. In the title case, all words are capitalized. Note that you need to include the System.Globalization namespace. The following sample illustrates its usage.

Download  Run Code

 
The above code will ignore the strings in all caps, such as “HTTPS”. In order to capitalize only the first character in the string and lower the rest, you can do like:

Download  Run Code

2. Using Regex

You can also use regular expressions to capitalize the first letter of each word in a string. Here’s what the code would look like:

Download  Run Code

That’s all about capitalizing the first letter of each word in a string in C#.