tags:

views:

61

answers:

3

For some reason, the syntax highlighting below is working how I'd like it to, but this is not how it interprets the code in Visual Studio. When I try to assign multiple lines to a string, it won't let me. Is there a way i can make the following work without combining all of my code into one line or using a += for each new line?

        string HtmlCode = "";
        HtmlCode =
            "
                <head>
                    <style>
                        *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}
                    </style>
                </head>
            ";
+10  A: 

Use verbatim string by prefixing your string with @

string HtmlCode = "";
HtmlCode =
        @"
            <head>
                <style>
                    *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}
                </style>
            </head>
        ";
madgnome
Oh wow, the @ works for multiple lines too! I thought it was only for the '\'. Anyway, thanks much, I learn something new all the time on Stack-O :)
Soo
+2  A: 

Use literal strings:

string HtmlCode = @"                
    <head>
        <style>
        *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}             
        </style>
    </head>";
Simon Steele
+2  A: 

Prefix the string with an "@"

    string HtmlCode = "";
    HtmlCode =
        @"
            <head>
                <style>
                    *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}
                </style>
            </head>
        ";
FacticiusVir