473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What is the '@' prefix infront of string?

Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )

Nov 26 '05 #1
10 17857
It represents a verbatim string literal.
http://msdn.microsoft.com/library/de...ec_2_4_4_5.asp

--
Tim Wilson
..NET Compact Framework MVP

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )

Nov 26 '05 #2
The @ sign in front of a string tells the compiler to ignore any embeded
escape sequences.

string "\"" would yield a single double quote.
string "\\" would yield a single back slash
string @"\\" would yield two backslashes

--

Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org
"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )

Nov 26 '05 #3

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )


The '@' symbol is the verbatim string marker. Basically it means that the
string shouldn't be escaped, that is the escapable characters '\n' for
newline and '\r' for line return, for example, won't be processed.
If written to the console, for example,
"this\nis\na\nline"
would print:
this
is
a
line

@"this\nis\na\nline"
would print:
this\nis\na\nline
Nov 26 '05 #4
Ann Huxtable <an**********@research-labs.de> wrote in
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
Why is it that sometimes strings used in C# are pre-pended by an
'@' character?. Is there any documentation on this (Google
searches don't bring anything useful - "c# + '@' + string
variables" etc )


Ann,

In addition to the other responses, putting the @ symbol in front of
a string literal allows you to do things like this:

string pageHtml = @"
<html>
<head>
<title>
My Page
<title>
</head>
<body>
Hello, world!
</body>
</html>";
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 26 '05 #5


Ann Huxtable wrote:
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )


many thanks all

Nov 26 '05 #6
Ann Huxtable wrote:
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this oogle searches don't bring
anything useful - "c# + '@' + string variables" etc )


http://msdn.microsoft.com/library/en...ec_2_4_4_5.asp

Practically speaking, it is handy if your string contains backslashes or
line breaks, because verbatim string literals may be multiline and the only
character that needs escaping is double quote. On the other hand, if your
string has a lot of double quotes in it, the regular string literal format
with \" escapes may be easier to read.

--
Chris Priede
Nov 26 '05 #7
Ann Huxtable <an**********@research-labs.de> wrote:
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )


See http://www.pobox.com/~skeet/csharp/s....html#literals

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 26 '05 #8
Besides the uses described in other replies, use of @ also allows keywords
to be used as identifiers.

public void (string @string)
{
Console.WriteLine("Value of string is {0}", @string);
}

IMO the fact that you *can* do this does imply that you *should* do it.

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )

Dec 4 '05 #9
"Ted Miller" <te*@millerzone.net> wrote in
news:11*************@corp.supernews.com:
Besides the uses described in other replies, use of @ also
allows keywords to be used as identifiers.

public void (string @string)
{
Console.WriteLine("Value of string is {0}", @string);
}

IMO the fact that you *can* do this does imply that you *should*
do it.


Ted,

Uhhh... Did you mean "does" or "doesn't"?
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Dec 4 '05 #10
Ted,

Yeah, the C# language specification mentions that this usage of it was
included for cross language support. The idea being that a keyword in
one language doesn't necessarily mean it is in another. Personally,
I've yet to encounter a reason for using it in this manner.

Brian

Ted Miller wrote:
Besides the uses described in other replies, use of @ also allows keywords
to be used as identifiers.

public void (string @string)
{
Console.WriteLine("Value of string is {0}", @string);
}

IMO the fact that you *can* do this does imply that you *should* do it.

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Why is it that sometimes strings used in C# are pre-pended by an '@'
character?. Is there any documentation on this (Google searches don't
bring anything useful - "c# + '@' + string variables" etc )


Dec 4 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mr_burns | last post by:
hi, if i have a datebase field like so: $username = $row; //after SELECT and mysql_query etc. how do i check what file type it is? i have tried using is_string to check it but it returns...
1
by: hlddn | last post by:
unicode or other? we what judge? thank all
2
by: Supra | last post by:
what is prefix for radiobutton1? regards
1
by: tggfang | last post by:
Please, anybody can tell me what is the real meaning of this const String& str thanks
6
by: Eric Moors | last post by:
If have a question with respect to the code below: ################################################################# #include <stdio.h> char *ret_ok(void) { static char str = "explicit...
1
by: DR | last post by:
how to determine what language a string is written in? is there any method to take a string and return what language it is in? e.g. english, hindi, spanish, etc.
0
by: python | last post by:
I understand that many portions of the string module are redundant with the native methods of strings and will removed in Python 3.0. Makes sense to me. But what will happen to the portions of...
0
by: Christian Heimes | last post by:
python@bdurham.com schrieb: See for yourself: http://svn.python.org/projects/python/branches/py3k/Lib/string.py Christian
4
Claus Mygind
by: Claus Mygind | last post by:
In my code I am sending a number of records via an ajax post method to the web-server for updating a table. I will parse the query string when it is received on the server side. But I am not sure...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.