.NET Tip: String Literals Without Escape Characters Wisconsin

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

Local Companies

R S InfoCon, Inc.
262-898-7456
2320 Renaissance Blvd
Sturtevant, WI
Xorbix Technologies Inc.
414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
R.E. Coker and Associates, Inc.
262-723-8104
108 W Court St.
Elkhorn, WI
Acumium
608 310 9700 x 522
5133 West Terrace Drive Suite 300
Madison, , WI
HarrisData
262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI
IFS
414-577-5191
12000 W. Park Place
Milwaukee, WI
Wireless Direct
1.866.707.8498
BOX 71101
shorewood, WI
Visionary Computer Solutions
262-365-9430
PO Box 406
Grafton, WI
Greenbrier & Russel
(920) 225-6800
1019 Truman St
Kimberly, WI
Larson Consulting
(920) 346-5876
127 E Main St
Brandon, 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 Local Company

Xorbix Technologies Inc.

414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
http://www.xorbix.com

Related Articles
- Primitives and Object Wrappers Wisconsin
Explore the various relationships among Java primitives, objects, and object wrappers. These are important concepts because the use of object wrappers is a very powerful technique and used in many applications.
- .NET Tip: Using a Parameter Array in Your Functions Wisconsin
- Internationalization Using String Resource References Wisconsin
- E-Commerce Tip: Programmatically Validate Credit Card Numbers Wisconsin
- .NET Tip: Converting Strings to Enum Values Wisconsin
Regional Articles
- .NET Tip: String Literals Without Escape Characters Appleton WI
- .NET Tip: String Literals Without Escape Characters Baraboo WI
- .NET Tip: String Literals Without Escape Characters Beaver Dam WI
- .NET Tip: String Literals Without Escape Characters Beloit WI
- .NET Tip: String Literals Without Escape Characters Brookfield WI
- .NET Tip: String Literals Without Escape Characters Burlington WI
- .NET Tip: String Literals Without Escape Characters Cedarburg WI
- .NET Tip: String Literals Without Escape Characters Chippewa Falls WI
- .NET Tip: String Literals Without Escape Characters Cudahy WI
- .NET Tip: String Literals Without Escape Characters De Pere WI
- .NET Tip: String Literals Without Escape Characters Delavan WI
- .NET Tip: String Literals Without Escape Characters Eau Claire WI
- .NET Tip: String Literals Without Escape Characters Elkhorn WI
- .NET Tip: String Literals Without Escape Characters Fond Du Lac WI
- .NET Tip: String Literals Without Escape Characters Fort Atkinson WI
- .NET Tip: String Literals Without Escape Characters Franklin WI
- .NET Tip: String Literals Without Escape Characters Green Bay WI
- .NET Tip: String Literals Without Escape Characters Hartland WI
- .NET Tip: String Literals Without Escape Characters Janesville WI
- .NET Tip: String Literals Without Escape Characters Kaukauna WI
- .NET Tip: String Literals Without Escape Characters Kenosha WI
- .NET Tip: String Literals Without Escape Characters La Crosse WI
- .NET Tip: String Literals Without Escape Characters Lake Geneva WI
- .NET Tip: String Literals Without Escape Characters Manitowoc WI
- .NET Tip: String Literals Without Escape Characters Marinette WI
- .NET Tip: String Literals Without Escape Characters Marshfield WI
- .NET Tip: String Literals Without Escape Characters Menasha WI
- .NET Tip: String Literals Without Escape Characters Menomonee Falls WI
- .NET Tip: String Literals Without Escape Characters Menomonie WI
- .NET Tip: String Literals Without Escape Characters Merrill WI
- .NET Tip: String Literals Without Escape Characters Middleton WI
- .NET Tip: String Literals Without Escape Characters Milwaukee WI
- .NET Tip: String Literals Without Escape Characters Mosinee WI
- .NET Tip: String Literals Without Escape Characters Mukwonago WI
- .NET Tip: String Literals Without Escape Characters Muskego WI
- .NET Tip: String Literals Without Escape Characters Neenah WI
- .NET Tip: String Literals Without Escape Characters New Berlin WI
- .NET Tip: String Literals Without Escape Characters Oak Creek WI
- .NET Tip: String Literals Without Escape Characters Oconomowoc WI
- .NET Tip: String Literals Without Escape Characters Onalaska WI
- .NET Tip: String Literals Without Escape Characters Oshkosh WI
- .NET Tip: String Literals Without Escape Characters Pewaukee WI
- .NET Tip: String Literals Without Escape Characters Racine WI
- .NET Tip: String Literals Without Escape Characters Rhinelander WI
- .NET Tip: String Literals Without Escape Characters Rice Lake WI
- .NET Tip: String Literals Without Escape Characters River Falls WI
- .NET Tip: String Literals Without Escape Characters Schofield WI
- .NET Tip: String Literals Without Escape Characters Shawano WI
- .NET Tip: String Literals Without Escape Characters Sheboygan WI
- .NET Tip: String Literals Without Escape Characters South Milwaukee WI
- .NET Tip: String Literals Without Escape Characters Stevens Point WI
- .NET Tip: String Literals Without Escape Characters Sturgeon Bay WI
- .NET Tip: String Literals Without Escape Characters Sun Prairie WI
- .NET Tip: String Literals Without Escape Characters Superior WI
- .NET Tip: String Literals Without Escape Characters Thiensville WI
- .NET Tip: String Literals Without Escape Characters Two Rivers WI
- .NET Tip: String Literals Without Escape Characters Watertown WI
- .NET Tip: String Literals Without Escape Characters Waukesha WI
- .NET Tip: String Literals Without Escape Characters Waupaca WI
- .NET Tip: String Literals Without Escape Characters Wausau WI
- .NET Tip: String Literals Without Escape Characters West Bend WI
- .NET Tip: String Literals Without Escape Characters Whitewater WI
- .NET Tip: String Literals Without Escape Characters Wisconsin Rapids WI
Related Articles
- Primitives and Object Wrappers Wisconsin
Explore the various relationships among Java primitives, objects, and object wrappers. These are important concepts because the use of object wrappers is a very powerful technique and used in many applications.
- .NET Tip: Using a Parameter Array in Your Functions Wisconsin
- Internationalization Using String Resource References Wisconsin
- E-Commerce Tip: Programmatically Validate Credit Card Numbers Wisconsin
- .NET Tip: Converting Strings to Enum Values Wisconsin
Related Local Events
2008 Early Stage Symposium
Dates: 11/5/2008 - 11/6/2008
Location: Monona Terrace
Madison WI
View Details

Wisconsin Entrepreneurs' Conference
Dates: 6/9/2008 - 6/10/2008
Location: Hyatt Regency Hotel
Milwaukee WI
View Details
Rate Article
     
Articles Insider

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

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