String Operations

C# Escape Sequence Listing

by Dave on November 10, 2009

in String Operations

What is an escape sequence? Well, put simply, an escape sequence is a series of special characters which are interpreted by the compiler as a command. In other words, they suspend the normal processing to perform some special function. In C#, escape sequences are represented by a ‘\’ (backslash) followed by a letter or a [...]

{ 6 comments }

New ASCII Codes Page

by Dave on October 7, 2009

in String Operations

I have added a new page to this blog called ASCII Codes, which can be accessed from the navigation bar at the top of the page. This new page is intended as a reference guide which you can use to look up an ascii code’s decimal, hexadecimal, and html values. There is also a description [...]

{ 1 comment }

Formatting Decimals in C#

by Dave on September 23, 2009

in String Operations

In this post I am going to show you a few different ways how you can format a decimal number (float, double, or decimal). Setting the Maximum Allowed Decimal Places To format your numbers to a maximum of two decimal places use the format string {0:0.##} as shown in the below example: string.Format(“{0:0.##}”, 256.583); // [...]

{ 0 comments }

Formatting Integers in C#

by Dave on September 21, 2009

in String Operations

In this post I am going to show you a few different ways how you can format an integer (int). Padding with Zeroes To pad your integer with zeroes write your format string with a colon (‘:’) and include as many zeroes as you wish after the colon ({0:[your zeroes]}). Below are a few examples. [...]

{ 1 comment }

Formatting a DateTime Object in C#

by Dave on September 18, 2009

in String Operations

In this post I have listed the different formatting options provided by .NET for a DateTime object. The examples shown below are based on the following DateTime object: // 18 September 2009 20:10:35 DateTime dt = new DateTime(2009, 09, 18, 20, 10, 35, 123); Format specifier Description Result dt.ToString(); To String 18/09/2009 20:10:35 dt.ToString(“d”); dt.ToShortDateString(); [...]

{ 0 comments }