.NET Tip: String Literals Without Escape Characters Avon Lake OH

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

Local Companies

Pointe Blank Solutions
440-243-5100
7055 Engle RD
Cleveland, OH
Software Under Flap
216-661-2000
4819 Bridge Ave
Cleveland, OH
Priority One Solutions
216-298-4020
2130 Superior Ave E
Cleveland, OH
Gecko Enterprises
(330) 475-0039
2197 Graham Rd
Stow, OH
Authentech Software Developers Inc
(330) 425-4538
Twinsburg, OH
Alvya Web Solutions
(440) 263-3227
23838 Delmere dr.
North Olmsted, OH
Angert Inc
440-891-1768
15833 Parklawn Ave
Cleveland, OH
Value Software
440-886-3211
5556 Pearl RD
Cleveland, OH
Application Design Consultants Inc
216-292-6636
2614 Butterwing RD
Cleveland, OH
Midwest Industrial Systems Inc
(440) 808-8900
29915 Sequoia Trl
Cleveland, OH

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

Alvya Web Solutions

4402633227
23838 Delmere dr.
North Olmsted, OH
http://alvya.com

A web development company that specializes in everything from ajax web 2.0 app development using php/mysql/ruby to brand identity and SEO.

Related Local Event
Earth Science Day
Dates: 10/17/2009 - 10/17/2009
Location: Cleveland Museum of Natural History
Cleveland, OH
View Details