简体   繁体   English

在c#中转义内联css

[英]Escape inline css in c#

I am trying to scape the follow snippet of inline styling for a html enabled email: 我正在尝试为支持html的电子邮件寻找内联样式的以下片段:

addressInformation.Append("<style> p {font-family:"Calibri", "Arial";} </style>");

I have tried escaping the double quotes with additional double quotes and curly braces with additional curly braces to no avail. 我试图用额外的双引号和带有额外花括号的花括号来转义双引号但无济于事。

How do I Escape this line? 我如何逃避这一行?

There are two choices: 有两种选择:

addressInformation.Append("<style> p {font-family:\"Calibri\", \"Arial\";} </style>");

addressInformation.Append(@"<style> p {font-family:""Calibri"", ""Arial"";} </style>");

And of course you can also bypass the need to escape: 当然,你也可以绕过逃跑的需要:

addressInformation.Append("<style> p {font-family:'Calibri', 'Arial';} </style>");

Or in this case, since the values are single words: 或者在这种情况下,因为值是单个单词:

addressInformation.Append("<style> p {font-family:Calibri, Arial;} </style>");

"逃脱了\\"

addressInformation.Append("<style> p {font-family:\"Calibri\", \"Arial\";} </style>");

' character should work, or \\" instead of just ". '角色应该工作,或者“而不仅仅是”。

addressInformation.Append("<style> p {font-family:'Calibri', 'Arial';} </style>"); addressInformation.Append("<style> p {font-family:"Calibri", "Arial";} </style>");

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

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