467,146 Members | 1,000 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

basic question

Hello,

I've noticed in some sample code that sometimes
people use the @ before a string when concatenating
them. Example:

string filePath = Appl.Request.PhysicalApplicationPath +
@"bin\" + asmname + ".dll";

Why is this done? What is the difference between using
the @ before the string and not using it? Thanks for
your help!
Nov 17 '05 #1
  • viewed: 1582
Share:
4 Replies
hi mark,
if you add the @ before a string the escape sequences are ignored. this has
nothing to do with concatenating.
i.e.
@"bin\" + asmname + ".dll";
and
"bin\\" + asmname + ".dll";
result in the same ..

the 2 following statments result in : the boy said "Hello".
@"the boy said ""Hello""."
"the boy said \"Hello\"."

Hope this helps
Karsten

"Mark Fox" <in**@solelsoftware.com> schrieb im Newsbeitrag
news:07****************************@phx.gbl...
Hello,

I've noticed in some sample code that sometimes
people use the @ before a string when concatenating
them. Example:

string filePath = Appl.Request.PhysicalApplicationPath +
@"bin\" + asmname + ".dll";

Why is this done? What is the difference between using
the @ before the string and not using it? Thanks for
your help!

Nov 17 '05 #2
Hello Mark,

@-quoted string literals start with @ and are enclosed in double quotation marks. For example:

@"good morning" // a string literal

The advantage of @-quoting is that escape sequences are not processed, which makes it easy to write, for example, a fully
qualified file name:

@"c:\Docs\Source\a.txt" // rather than "c:\\Docs\\Source\\a.txt"

To include a double quotation mark in an @-quoted string, double it:
@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.

Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Mark Fox" <in**@solelsoftware.com>
!Sender: "Mark Fox" <in**@solelsoftware.com>
!Subject: basic question
!Date: Wed, 23 Jul 2003 00:07:18 -0700
!Lines: 12
!Message-ID: <07****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNQ6Q4O+P0RyAbqSfOMJUE4aJxN3A==
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:161258
!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Hello,
!
! I've noticed in some sample code that sometimes
!people use the @ before a string when concatenating
!them. Example:
!
!string filePath = Appl.Request.PhysicalApplicationPath +
!@"bin\" + asmname + ".dll";
!
!Why is this done? What is the difference between using
!the @ before the string and not using it? Thanks for
!your help!
!
Nov 17 '05 #3
Thank you so much for explaining this. I understand what
it does now!
-----Original Message-----
Hello Mark,

@-quoted string literals start with @ and are enclosed in double quotation marks. For example:
@"good morning" // a string literal

The advantage of @-quoting is that escape sequences are not processed, which makes it easy to write, for example,
a fullyqualified file name:

@"c:\Docs\Source\a.txt" // rather than "c:\\Docs\\Source\\a.txt"
To include a double quotation mark in an @-quoted string, double it:@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.
Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Content-Class: urn:content-classes:message
!From: "Mark Fox" <in**@solelsoftware.com>
!Sender: "Mark Fox" <in**@solelsoftware.com>
!Subject: basic question
!Date: Wed, 23 Jul 2003 00:07:18 -0700
!Lines: 12
!Message-ID: <07****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNQ6Q4O+P0RyAbqSfOMJUE4aJxN3A==
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:161258!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Hello,
!
! I've noticed in some sample code that sometimes
!people use the @ before a string when concatenating
!them. Example:
!
!string filePath = Appl.Request.PhysicalApplicationPath +!@"bin\" + asmname + ".dll";
!
!Why is this done? What is the difference between using
!the @ before the string and not using it? Thanks for
!your help!
!
.

Nov 17 '05 #4
Hello,

You are welcome. :) Thanks for participating in community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Mark Fox" <in**@solelsoftware.com>
!Sender: "Mark Fox" <in**@solelsoftware.com>
!References: <07****************************@phx.gbl> <lb**************@cpmsftngxa06.phx.gbl>
!Subject: RE: basic question
!Date: Wed, 23 Jul 2003 03:59:58 -0700
!Lines: 74
!Message-ID: <0a****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNRCY54Gk5IwRKnTeGHtC7K60Mctg==
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:161313
!NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Thank you so much for explaining this. I understand what
!it does now!
!
!>-----Original Message-----
!>Hello Mark,
!>
!>@-quoted string literals start with @ and are enclosed
!in double quotation marks. For example:
!>
!>@"good morning" // a string literal
!>
!>The advantage of @-quoting is that escape sequences are
!not processed, which makes it easy to write, for example,
!a fully
!>qualified file name:
!>
!>@"c:\Docs\Source\a.txt" // rather
!than "c:\\Docs\\Source\\a.txt"
!>
!>To include a double quotation mark in an @-quoted
!string, double it:
!>@"""Ahoy!"" cried the captain." // "Ahoy!" cried the
!captain.
!>
!>Thanks.
!>
!>Best regards,
!>Yanhong Huang
!>Microsoft Online Partner Support
!>
!>Get Secure! - www.microsoft.com/security
!>This posting is provided "AS IS" with no warranties, and
!confers no rights.
!>
!>--------------------
!>!Content-Class: urn:content-classes:message
!>!From: "Mark Fox" <in**@solelsoftware.com>
!>!Sender: "Mark Fox" <in**@solelsoftware.com>
!>!Subject: basic question
!>!Date: Wed, 23 Jul 2003 00:07:18 -0700
!>!Lines: 12
!>!Message-ID: <07****************************@phx.gbl>
!>!MIME-Version: 1.0
!>!Content-Type: text/plain;
!>! charset="iso-8859-1"
!>!Content-Transfer-Encoding: 7bit
!>!X-Newsreader: Microsoft CDO for Windows 2000
!>!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!>!Thread-Index: AcNQ6Q4O+P0RyAbqSfOMJUE4aJxN3A==
!>!Newsgroups: microsoft.public.dotnet.framework.aspnet
!>!Path: cpmsftngxa06.phx.gbl
!>!Xref: cpmsftngxa06.phx.gbl
!microsoft.public.dotnet.framework.aspnet:161258
!>!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
!>!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!>!
!>!Hello,
!>!
!>! I've noticed in some sample code that sometimes
!>!people use the @ before a string when concatenating
!>!them. Example:
!>!
!>!string filePath = Appl.Request.PhysicalApplicationPath
!+
!>!@"bin\" + asmname + ".dll";
!>!
!>!Why is this done? What is the difference between using
!>!the @ before the string and not using it? Thanks for
!>!your help!
!>!
!>
!>
!>.
!>
!
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by pauldepstein@att.net | last post: by
9 posts views Thread by Malcolm | last post: by
4 posts views Thread by Ramesh | last post: by
5 posts views Thread by Aussie Rules | last post: by
4 posts views Thread by MikeB | last post: by
3 posts views Thread by Scott Stark | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.