SIGN UP MEMBER LOGIN:    
ARTICLE

Verbatim String Literals

Posted by Hari Shankar Articles | String in C# March 01, 2001
I used to wonder, if I could somehow represent "\" as "\" instead of the escape sequence for black slash ("\\") in string.
Reader Level:
Download Files:
 

Description:

I used to wonder, if I coud somehow represent "\" as "\" instead of the escape sequence  for black slash ("\\") in string. I have precisely come across this feature today in C-sharp and I would like to share it with you all.Especially in my last articles when I used the paths I did not feel like using "\\".

Other than the regular string literals, C# supports what is called as Verbatim string literals.Verbatim string literals begin with @" and end with the matching quote. They do not have escape sequences.

So the statement:

test=@"c:\tEST\TEST.doc";

is same as:

test="c:\\tEST\\TEST.doc";

What is needed to compile?

.NET SDK

How to Compile?

csc testVerbatimStrings.cs

Source Code:

using System;
public class TestVerbatimStrings
{
public static void Main()
{
string test;
test=@"c:\tEST\TEST.doc";
Console.WriteLine(test);
string test2;
test2="c:\\tEST\\TEST.doc";
Console.WriteLine(test2);
// @"c:\tEST\TEST.doc" is same as "c:\\tEST\\TEST.doc"
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor