.NET Tip: String Literals Without Escape Characters Charlotte NC

Use @-quoted strings to avoid escape characters in your string literals.

Local Companies

Collabera
(704) 372-7272
212 South Tryon Street
Charlotte, NC
CompuData, Inc
(704) 504-0600
2401 Whitehall Park Drive
Charlotte, NC
SunGard Asset Management Systems
(704) 527-6300
PO Box 240882
Charlotte, NC
Oracle Corporation
(704) 423-1450
2550 West Tyvola Road
Charlotte, NC
StreamLogic Inc.
704-771-1090
3030 Glen Summit Dr.
Charlotte, NC
Ironworks Consulting, LLC
(704) 494-8889
3440 Toringdon Way, Suite 205
Charlotte, NC
InterDyn Artis
(704) 846-6750
8100 Tower Point Drive
Charlotte, NC
A3 Technologies, Inc
704-708-3872
2300 sardis Rd North
Charlotte, NC
Software Toolbox Inc
(704) 849-2773
148A East Charles Street
Charlotte, NC
Business Control Systems Inc
(704) 333-7794
402 W Trade St
Charlotte, NC

provided by: 
Originally published at Internet.com


Today's tip is a very simple one, but if you are like me you will find yourself using it frequently. Do you have string literals that are filled with escape characters because they include characters that have a special meaning? One of the most common places you will find this is in file paths. If you don't want to have to worry about getting all of the backslashes correct, try using an @-quoted string instead. Say you have a variable like the following in your application: string AppDataFile = "C:\\Program Files\\My Application \\MyApp.dat";

This works fine, but can be hard to read and is more likely to be prone to errors if you do not escape all of the backslashes correctly. Another option, using @-quoted strings, removes the need to escape the backslashes. The @-quoted version of the above example looks like this: string AppDataFile = @"C:\Program Files\My Application \MyApp.dat";

The only changes are the addition of the @ sign before the opening quotation mark and the removal of the backslash to escape the other backslashes. This format matches the way you see file and directory paths displayed everywhere else in Windows. You can use @-quoted strings for more than paths, so take a look at your use of string literals and see where you can simplify you code and make it more readable.

About the Author

Jay Miller is a Software Engineer with Electronic Tracking Systems, a company dedicated to robbery prevention, apprehension, and recovery based in Carrollton, Texas. Jay has been working with .NET since the release of the first beta and is co-author of Learn Microsoft Visual Basic.Net In a Weekend. Jay can be reached via email at jmiller@sm-ets.com.

Author: Jay Miller

Read article at Internet.com site

Featured Local Company

Collabera

(704) 372-7272
212 South Tryon Street
Charlotte, NC

Related Local Events
Automation Technology Expo South
Dates: 4/28/2010 - 4/29/2010
Location: Charlotte Convention Center
Charlotte, NC
View Details

Green Manufacturing Expo-Charlotte
Dates: 4/28/2010 - 4/29/2010
Location: Charlotte Convention Center
Charlotte, NC
View Details

Technology Summit: Technology + Innovation = Our Future
Dates: 11/18/2009 - 11/18/2009
Location: Hilton Charlotte Center City
Charlotte, NC
View Details

NCTA Congressional Briefing: Featuring U.S. Representatives Sue Myrick and Larry Kissell
Dates: 11/2/2009 - 11/2/2009
Location: Charlotte Chamber - Belk Action Center
Charlotte, NC
View Details

SOUTH-TEC
Dates: 10/6/2009 - 10/8/2009
Location: Charlotte Convention Center
Charlotte, NC
View Details