Difference Between Escape Character ("\") & Date Separator ("/") in LightSwitch 2012

This article describes the differences and use of the Escape Character ("\") and Date Separator ("/") Custom Format Specifier in LightSwitch Visual Studio 2012.

Escape Character ("\") Custom Format Specifier

The Escape Character in a format string is interpreted as a custom format specifier instead of a literal character. To prevent the character from being interpreted as a format specifier you can precede it with a backslash (\), in other words with an escape character.


Date Separator ("/") Custom Format Specifier

The "/" Custom Format Specifier is also known as the Date Separator for separating years, months and days. This date separator is retrieved from the DateTimeFormatInfo.DateSeparator property.

Note: Suppose the "/" format specifier is used without any other custom format specifiers, then it is interpreted as a standard date and time format specifier and will throw a FormatException.

Use the following procedure to create a sample showing how to use the Escape Character("\") and Date Separator("/") Custom Format Specifier on a Screen.

Step 1

Open the LightSwitch Application in Visual Studio 2012 and go to the Solution Explorer.

Solution Explorer

Right-click on "Data Sources" and choose "Add Table".

Add Table

The table appears in the Table Designer window. Insert the records in the following table.

Employee Table

Step 2

Now once again go to the Solution Explorer, right-click on Screens and choose Add Screen option.

Add Screen

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, inside screen information, choose "Employee" under screen data and provide some name to the Screen and click the "OK" button.

Add New Screen

The Screen Designer appears as shown below.

Screen Designer

Press F5 to run the application. Provide the information; we will get the following output. 

Output of Editable Grid Screen

Step 3

Escape Character("\") Custom Format Specifier

Now stop debugging the application. From the Table Designer select the "DOJ" record as shown in the figure below.

Select DOJ from Employee

Then go to the Format Pattern of Property window in the Table Designer and enter "h\h" in the format pattern for Escape Character Format Specifier as shown below.


Escape Character in Format Pattern Property

Once again press F5 to run the application. This time we will get the following output.

Output using Escape Character

Step 4

Date Separator ("/") Custom Format Specifier

Once again stop debugging the application and 
select the "DOJ" record from the table.

Now go to the Format Pattern of Property window in the Table Designer and this time enter "MM/dd" in the format pattern for Date Separator Format Specifier as shown below.

Date Separator Property Window

Once again press F5 to run the application. This time we will get the following output.

Output using Date Separator

Up Next
    Ebook Download
    View all
    Learn
    View all