-
March 29th, 2012, 01:59 AM
#1
@ string
what the result of the following strings:
@""""
@""","
I think:
""
",
Am I right?
Thank you
-
March 29th, 2012, 06:32 AM
#2
Re: @ string
yes, you got
Code:
" which is codable also as string s= "\"";
and
", which si codable aslo as string s2="\",";
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
March 29th, 2012, 06:58 AM
#3
Re: @ string
Cimperiali,
so @"""" is "" or "
Thank you for your help
-
March 29th, 2012, 07:07 AM
#4
Re: @ string
Normally (without using the @ symbol), when you type in ", it ends the string - so, to prevent this, you must use an escape sequence \" wherever you want " to appear as a part of the string.
Now, @ denotes verbatim strings, which ignore escape sequences and line breaks (useful for paths, for example). However, typing " still ends the string literal, and you can't use \" anymore, so a different approach is used - whenever you need " as a part of your string, you type in "".
So, @"""" is actually ".
This is something you can easily test yourself; just write a simple program that prints out a string variable, and then experiment a bit.
Code:
// in Main()
string test = @""""; // change this string literal, then run again
Console.WriteLine(test);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|