.NET Tip: String Literals Without Escape Characters Rhinelander WI

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

Local Companies

Desco Dental Systems Llc
(414) 281-9192
5005 W Loomis Rd
Milwaukee, WI
Jelltech Consulting
(262) 373-1350
21180 W Capitol Dr
Pewaukee, WI
Jela Company Inc
(920) 992-3900
N4977 County Road Ss
Rio, WI
Ray Jackson & Associates Custom Software Inc
(608) 839-4747
4704 Pierceville Rd
Cottage Grove, WI
Babbage's Etc
(414) 421-8290
5300 S 76th St
Greendale, WI
Statpac Inc
(715) 442-2261
1200 1st St
Pepin, WI
Computerjack
(920) 730-8200
W6232 Contractor Dr
Appleton, WI
Becker Technology Inc
(262) 628-3531
3051 Beechwood Industrial
Hubertus, WI
Advanced Information Management Inc
(920) 996-2380
1648 Tri Park Way
Appleton, WI
Link Development Corp
(262) 641-9911
12660 W North Ave
Brookfield, WI

.NET Tip: String Literals Without Escape Characters

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 National Company

Hult International Business School

617-238-5282
1 Education Street
Cambridge, MA
http://www.hult.edu

Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Home Services Retail & Consumer Services
Business Services Entertainment Industrial Goods & Services Software
Career Family Insurance Technology
Cars Financial Services Internet Telecommunications
Computer Hardware Food & Beverage Legal Transportation & Logistics
Construction Health Pets Travel
Education Home Electronics Real Estate Wedding