"\" Escape Character in LightSwitch 2012

This article explains how to use the Escape Character in LightSwitch Visual Studio 2012.

To prevent characters from being interpreted as a format string specifier, precede it with the escape character, the "\" symbol. This "\" symbol signifies that the following character is a character literal that must be included in the unchanged output string.

Note: To include a backlash in a string, you must escape with another backslash symbol, in other words "\\".

Use of Escape Character

The Escape Character causes the next character to be interpreted as a literal rather than as a custom format specifier.

Use the following procedure to create a sample showing how to use the Escape Character 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.

Student Table

Step 2

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

Add Screen

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

Add New Screen

The Screen Designer appears as shown below.

Application Designer

Step 3

Press F5 to run the application. Provide the information. 

Output for editable Screen

Step 4

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

Select Fees from Student

Then go to the Format Pattern of Property window in the Table Designer and enter "\####\#" in the format pattern as shown.

Format pattern Properties

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

output for escape characters

Step 5
 
Now to add an additional backslash to the format pattern.
 
Once again stop debugging the application and
go to the Format Pattern of the Property window in the Table Designer. This time enter "\##\\##\#" in the format pattern of the Property window. Here 4 represents 4 digits that will be there after the decimal places. 

Format pattern with double backslash
 
Once again press F5 to run the application. This time we will get the following output.

output for double backslash


Similar Articles