Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - @"string"

Reply
 
Old 07-08-2008   #1 (permalink)
Mike Gleason jr Couturier


 
 

@"string"

Why do I see a @ preceding strings in code examples?

What does the @ do?


thanks!



My System SpecsSystem Spec
Old 07-08-2008   #2 (permalink)
Miro


 
 

Re: @"string"

Do you mean for 'parameters' in sql statements?

Can you post an example of what you see?


"Mike Gleason jr Couturier" <nospam@xxxxxx> wrote in message
news:urljRJQ4IHA.3500@xxxxxx
Quote:

> Why do I see a @ preceding strings in code examples?
>
> What does the @ do?
>
>
> thanks!
>
My System SpecsSystem Spec
Old 07-08-2008   #3 (permalink)
Rory Becker


 
 

Re: @"string"

Hello Mike Gleason jr Couturier,
Quote:

> Why do I see a @ preceding strings in code examples?
>
> What does the @ do?
I believe it is a c# sytax that prevents the compiler otherwise interpreting
certain characters as escape codes.

for example
-------------------------------------------------------------
string SomeString = "\n"; //This produces an enter keystroke
string OtherString = @"\n"; //This produces a string containing the backslash
and 'n' characters.
-------------------------------------------------------------


--
Rory


My System SpecsSystem Spec
Old 07-08-2008   #4 (permalink)
Anthony Jones


 
 

Re: @"string"

"Rory Becker" <rorybecker@xxxxxx> wrote in message
news:3af1034718d0c8caaf282538db6d@xxxxxx
Quote:

> Hello Mike Gleason jr Couturier,
>
Quote:

> > Why do I see a @ preceding strings in code examples?
> >
> > What does the @ do?
>
> I believe it is a c# sytax that prevents the compiler otherwise
interpreting
Quote:

> certain characters as escape codes.
>
> for example
> -------------------------------------------------------------
> string SomeString = "\n"; //This produces an enter keystroke
> string OtherString = @"\n"; //This produces a string containing the
backslash
Quote:

> and 'n' characters.
> -------------------------------------------------------------
>
Correct and in addition a string preceded with @ can split across lines:-

string someSQL = @"
SELECT a.Field1, a.Field2
FROM ATable a
INNER JOIN BTable b ON b.ID = a.ID
WHERE b.Field3 = 15"

The down side is that " need to be duplicated as "" e.g.:-

string someXML = @"<root thing=""x"" />"





--
Anthony Jones - MVP ASP/ASP.NET


My System SpecsSystem Spec
Old 07-08-2008   #5 (permalink)
Jon Skeet [C# MVP]


 
 

Re: @"string"

Mike Gleason jr Couturier <nospam@xxxxxx> wrote:
Quote:

> Why do I see a @ preceding strings in code examples?
>
> What does the @ do?
See http://pobox.com/~skeet/csharp/strings.html

--
Jon Skeet - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
My System SpecsSystem Spec
Old 07-08-2008   #6 (permalink)
Mike Gleason jr Couturier


 
 

Re: @"string"

Ok thanks guys...

I was seeing the @ when declaring connection strings in books... (web
projetcs, web.config)

Thanks!


My System SpecsSystem Spec
Old 07-08-2008   #7 (permalink)
Miro


 
 

Re: @"string"

You should also read up on
"SQL Injections"... just google it up

It will give you good examples of why the @ is used as a parameter.


"Mike Gleason jr Couturier" <nospam@xxxxxx> wrote in message
news:OL51DOS4IHA.1196@xxxxxx
Quote:

> Ok thanks guys...
>
> I was seeing the @ when declaring connection strings in books... (web
> projetcs, web.config)
>
> Thanks!
>
My System SpecsSystem Spec
Old 07-09-2008   #8 (permalink)
Garfilone


 
 

Re: @"string"

On Jul 8, 9:55*pm, "Mike Gleason jr Couturier"
<nos...@xxxxxx> wrote:
Quote:

> Why do I see a @ preceding strings in code examples?
>
> What does the @ do?
>
> thanks!
with this symbol you could go without escape chars, for example

without @: var str="e:\\folder1\\folder2\\folder3\\file"

with @: var str=@"e:\folder1\folder2\folder3\file"
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
wscript.echo only a new line / embed a "CR" in a text string ? VB Script
DVD Maker "invalid class string" during transcode Vista music pictures video
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Vista General
how to get "select @@version" to display one long string PowerShell
"string STR_ERR_OS was not found in string table" Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46