views:

772

answers:

6

In Visual Studio with C#, how can I declare a string inside of a string like this? I saw a few Stack Overflow pages like "Java string inside string to string", but didn't think any of them were the same as my question.

Basically if I have

"<?xml version="1.0" encoding="UTF-8"standalone="yes" ?>"

How can I declare this, or something like it, in my code as a string? Someone suggested double quotations to me around things like ""1.0"", but I couldn't get that to work.

Thanks for the help.

A: 

Try this:

string myString = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>"
Fredrik Mörk
+12  A: 

Either escape the double quotes like this:

"<?xml version=\"1.0\" encoding=\"UTF-8\"standalone=\"yes\" ?>"

or use a verbatim string (notice the leading @ symbol in front of the string) like this:

@"<?xml version=""1.0"" encoding=""UTF-8""standalone=""yes"" ?>"
Andrew Hare
Thanks so much!
+4  A: 

Either:

@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>"

or

"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"

or more simply; use single quotes!

"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"
Marc Gravell
+1 For single quotes.
Andrew Hare
+1  A: 
String myString = "<?xml version=\"1.0\" encoding=\"UTF-8\"standalone=\"yes\" ?>";
Olivier PAYEN
A: 

You can escape the quotation marks: http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88415.aspx.

Sinan Ünür
A: 

+1 For single quotes

cora