Double problem with Qoutes with string

Is there a way to write in Visual Studio with good formatting for the line below?

string x = "<Site name=\"Stack Overflow\" >Inner Content</Site>";

      

so it looks like this:

string x= "<Site name="Stack Overflow">
           Inner content;
          </Site>"

      

+1


a source to share


2 answers


Have you tried using a string literal?

string x= @"<Site name=""Stack Overflow"">
           Inner content;
          </Site>"

      



I'm not really sure what is what you are asking for. Do you want to see if you can get Visual Studio to format your code to look like this? If so, there is no way in the C # editor to do this.

+6


a source


I'm not 100% sure what you are looking for. If you want it to look good in VS, you can do something like this:

string x = "<Site name=\"Stack Overflow\">" + 
           "Inner Content" + 
           "</Site>";

      

I'm sure you need escaping quotes in C ++ / C #. I don't know how to avoid this if you don't load the character at once.



If you want to add return values ​​to the resulting string, you can simply in \ n like this:

string x = "<Site name=\"Stack Overflow\">\nInner Content\n</Site>";

      

+1


a source







All Articles