简体   繁体   English

Visual C# 逐字字符串语法问题

[英]Visual C# verbatim string syntax problem

I am trying to create a string literal in visual C sharp.我正在尝试在视觉 C 中创建一个字符串文字。 i don't know why VS is throwing errors about the html test i have inserted the @ "" should allow multi line and be literal from what i have read, what am i doing wrong?我不知道为什么VS会抛出关于html测试的错误我插入了@“”应该允许多行并且从我读过的内容来看是字面意思,我做错了什么?

string test = @" 

        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>

        <style type="text/css">
                        body{font-family:helvetica;}
                        body{font-size:10px;}
                        table{ border-collapse:collapse; } 
                        table{border:2px solid black; }
                        table{font-family:helvetica;}
                        table{font-size:17px;}
                        td{border:1px solid #D2B9D3;}
                        td{font-family:helvetica;}
                        td{font-size:18px;}
                        th{border:1px solid black;}
                        .style4 {font-size: 36px}
        </style>

        </head>

        ";

You have to replace " to "" in your html text and it will be fine您必须在 html 文本中将“替换为”,这样就可以了

EDIT: I just read further on and yes it seems that "" is the correct route since it's a verbatim string.编辑:我只是继续阅读,是的,似乎“”是正确的路线,因为它是逐字字符串。

Actually "" is a VB.NET thing, in C# you will want \" to escape the quotes. 实际上 ""是一个 VB.NET 的东西,在 C# 你会希望 \"转义引号。

Here are some others, for your reference.这里有一些其他的,供您参考。

http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/what-character-escape-sequences-are-available.aspx http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/what-character-escape-sequences-are-available.aspx

I found that using ' in place of " also works for your specific situation.我发现使用 ' 代替 " 也适用于您的具体情况。

@"<html xmlns='http://www.w3.org/1999/xhtml'>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM