.NET

C# Capitalize First Letters of Words

When gathering user input, especially in a free form text box, users will enter something like their first and last name but will not capitalize the first letters for the name. Then later, you may want to display the name and you find that it doesn't look very nice and is harder to read because of lack of capitalization.

The below code will take a value such as "john doe" and return it as the string "John Doe". You can even use the below code to format something like a blog title where you want each word to be capitalized.

	

C# Escape XML String

There are a lot of XML parsers out there that take a string and attempt to escape out all of the known XML characters. This is usually done when you want to place a user-entered string into XML and don't have much control over the content. I've seen regular expressions and string replaces that do some of this pretty well but many have edge cases they do not cover.

Some have just given up on this and instead used XML's nice "cheat" of placing the text in a CDATA section. Using CDATA, your XML element would like this:

	

Launch URL in Default Browser using C#

After deploying an application using the standard way of launching a URL in the default browser:

System.Diagnostics.Process.Start("http://www.google.com");

We found that almost randomly, an exception is thrown on certain user's machines when this method is called. I did some research and a couple of interesting posts came up.