By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

Why does @"""" result in "\""" ??

P: n/a
I posted a related problem today. The problem is this:

string str1 = @"""";

When I execute this code (even in a bare bones application), in the
IDE it returns "\"""

Why? Even in the immediate window it return this. Anywhere where I
attempt to use two apostrophes, it inserts a backslash. Even a
function in one method that saves its string to a file shows that the
backslash is really present because it also gets saved to the file. I
thought maybe just the IDE was having a "display" problem, but that
backslash really is in the string.

I used the repair feature of the VS.NET feature but it didn't help.
This morning I ran an Update on my complete system from Microsoft's
Update Website and I am certain that it has done something to the .NET
framework.

Any help is appreciated.

Thanks,
Johann Blake
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Johann, those two strings are equal. @"""" =="\""

The @ specifies that the string should be taken literally. The double "'s
indicate that that " shouldn't be considered a string terminator but instead
should be printed. The \" is an escape sequence which again specifies that
the " should not be considered as a string terminator but a ". When I run
the following code I get a single " as I should. In the IDE I do see the
"\"" but that's just how the IDE displays an escaped ". You should not see
the \ in any of the output. If you can reproduce this in a simple program
like I included below feel free to post it so we can check it out.

static void Main(string[] args)
{
string str1 = @"""";
Console.WriteLine(str1);
Console.Read();
}

--
Greg Ewing [MVP]
http://www.citidc.com

"Johann Blake" <jb****@closerworlds.com> wrote in message
news:a6**************************@posting.google.c om...
I posted a related problem today. The problem is this:

string str1 = @"""";

When I execute this code (even in a bare bones application), in the
IDE it returns "\"""

Why? Even in the immediate window it return this. Anywhere where I
attempt to use two apostrophes, it inserts a backslash. Even a
function in one method that saves its string to a file shows that the
backslash is really present because it also gets saved to the file. I
thought maybe just the IDE was having a "display" problem, but that
backslash really is in the string.

I used the repair feature of the VS.NET feature but it didn't help.
This morning I ran an Update on my complete system from Microsoft's
Update Website and I am certain that it has done something to the .NET
framework.

Any help is appreciated.

Thanks,
Johann Blake

Nov 15 '05 #2

P: n/a
Hi Johann,

That's the expected behavior, you see there is two forms of write a string
consisting of a " character:
@"""" or "\""

these are two forms of saying the same thing.

the IDE is always display such expression in the same way, using the escape
sequence.
if you do a Console.Write( ) you will see the same result on both cases.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Johann Blake" <jb****@closerworlds.com> wrote in message
news:a6**************************@posting.google.c om...
I posted a related problem today. The problem is this:

string str1 = @"""";

When I execute this code (even in a bare bones application), in the
IDE it returns "\"""

Why? Even in the immediate window it return this. Anywhere where I
attempt to use two apostrophes, it inserts a backslash. Even a
function in one method that saves its string to a file shows that the
backslash is really present because it also gets saved to the file. I
thought maybe just the IDE was having a "display" problem, but that
backslash really is in the string.

I used the repair feature of the VS.NET feature but it didn't help.
This morning I ran an Update on my complete system from Microsoft's
Update Website and I am certain that it has done something to the .NET
framework.

Any help is appreciated.

Thanks,
Johann Blake

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.