单引号在c#string中用双引号括起来 [英] single quotes with in double quotes in c# string

查看:107
本文介绍了单引号在c#string中用双引号括起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我在c#代码中遇到问题,分配到下面的字符串,但它不适合使用单引号。



Dear All,
I am getting problem in c# code to assign below string but its not proper working with single quotes.

string HighSlide = @"<a style='border: none;' href='CompanyMaster.aspx?popup=true'<br />
                                        önclick='return hs.htmlExpand(this, { objectType: 'iframe', align: 'left', width: 810, height: 520 });'><br />
                                       " + e.Day.Date.Day + "</a>";



当我在浏览器上看到这一行时,它会生成如下字符串。




When I see this line on browser it generate like below string.

string HighSlide = @"<a style='border: none;' href='CompanyMaster.aspx?popup=true'
                                         önclick='return hs.htmlExpand(this, { objectType: " + "''" + @"iframe" + "\'" + @", align: " + "\'" + @"left" + "\'" + @", width: 810, height: 520 });'>
                                       " + e.Day.Date.Day + "</a>";



请帮助纠正同样的问题。



先谢谢你。


Please help to correct for the same.

Thank you in advanced.

推荐答案

您需要用双引号替换onclick中的单引号(如先前Timberbird建议的那样)或用双引号替换对象文字中的单引号。如果您在HTML文档中对此片段进行硬编码,情况也是如此。
You need to either replace the single quotes from onclick with double quotes (as previously suggested by Timberbird) or replace the single quotes in the object literal with double quotes. The same would be true if you hard-coded this snippet in an HTML document.


亲爱的所有人,

我得到了解决方案,因为我使用了&#39我收到错误时的前缀和后缀。



示例:&#39frame&#39它将自动生成类似'frame'。



非常感谢你的帮助。
Dear All,
I got the solution as I used &#39 prefix and suffix when I got the error.

example : &#39frame&#39 Its will automatically generate like 'frame'.

Thank You very much for your help.


这篇关于单引号在c#string中用双引号括起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆