Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String inside of a string Ex: pie = "He said "hi"" - C#

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.

like image 954
user84613 Avatar asked Jun 03 '09 12:06

user84613


2 Answers

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"" ?>"
like image 50
Andrew Hare Avatar answered Oct 03 '22 15:10

Andrew Hare


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' ?>"
like image 41
Marc Gravell Avatar answered Oct 03 '22 14:10

Marc Gravell