Different URI encoding formats in C#


Ever need to encode a string of text to make it web-compliant in some way but didn’t know which encoding function to use? I recently stumbled across a StackOverflow post where a user has provided a sample table of the different encodings provided by the HttpUtility and Uri classes in C# and thought I would share it here. As an example, this is what is provided for the greater-than sign (>):

Unencoded: >
HttpUtility.UrlEncode: %3e
HttpUtility.UrlEncodeUnicode: %3e
HttpUtility.UrlPathEncode: >
Uri.EscapeDataString: %3E
Uri.EscapeUriString: %3E
HttpUtility.HtmlEncode: >
HttpUtility.HtmlAttributeEncode: >
Uri.HexEscape: %3E

If you do any kind of web or api development you’ll already see how useful this can be. Here is the link to the full table: http://stackoverflow.com/a/11236038/1068266

Enjoy!