原语句:
sb.Append( " <a href= "fdsfds " title= "gfsdf " onmouseover= "tip(this) " onmouseout= "document.all.pop.style.display= 'none ' "> fdsfds </a> ")
要把里面的这行进行转义,如何写?
<a href= "fdsfds " title= "gfsdf " onmouseover= "tip(this) " onmouseout= "document.all.pop.style.display= 'none ' "> fdsfds </a>
------解决方案--------------------------------------------------------
前面加@,把 "替换成 '
------解决方案--------------------------------------------------------
@ " <a href= " "fdsfds " " title= " "gfsdf " " onmouseover= " "tip(this) " " onmouseout= " "document.all.pop.style.display= 'none ' " "> fdsfds </a> "
------解决方案--------------------------------------------------------
@这个就行了。
------解决方案--------------------------------------------------------
所有双引号加上反斜杠就行了
<a href=\ "fdsfds\ " title=\ "gfsdf\ " onmouseover=\ "tip(this)\ " onmouseout=\ "document.all.pop.style.display= 'none '\ "> fdsfds </a>
------解决方案--------------------------------------------------------
sb.Append(@ " <a href= "fdsfds " title= "gfsdf " onmouseover= "tip(this) " onmouseout= "document.all.pop.style.display= 'none ' "> fdsfds </a> ")
------解决方案--------------------------------------------------------
楼上的有问题,@不能转义双引号,如果字符串中一定要有双引号,就不能使用@
------解决方案--------------------------------------------------------
sb.Append( " <a href= 'fdsfds ' title= 'gfsdf ' onmouseover= 'tip(this) '
onmouseout= 'document.all.pop.style.display=\ "none\ " '> fdsfds </a> ")
or
sb.Append( " <a href=\ "fdsfds\ " title=\ "gfsdf\ " onmouseover=\ "tip(this)\ " onmouseout=\ "document.all.pop.style.display= 'none '\ "> fdsfds </a> ")
------解决方案--------------------------------------------------------
sb.Append(@ " <a href= " "fdsfds " " title= " "gfsdf " " onmouseover= " "tip(this) " " onmouseout= " "document.all.pop.style.display= 'none ' " "> fdsfds </a> ");或: sb.Append( " <a href=\ "fdsfds\ " title=\ "gfsdf\ " onmouseover=\ "tip(this)\ " onmouseout=\ "document.all.pop.style.display= 'none '\ "> fdsfds </a> ");
------解决方案--------------------------------------------------------
用 @ 引起来的字符串以 @ 开头,并用双引号引起来。例如:
Vs帮助:ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/csref/html/vclrfString.htm
@ "good morning " // a string literal
用 @ 引起来的优点在于换码序列“不”被处理,这样就可以轻松写出字符串,例如一个完全限定的文件名:
@ "c:\Docs\Source\a.txt " // rather than "c:\\Docs\\Source\\a.txt "
若要在一个用 @ 引起来的字符串中包括一个双引号,请使用两对双引号:
@ " " "Ahoy! " " cried the captain. " // "Ahoy! " cried the captain.
@ 符号的另一种用法是使用碰巧成为 C# 关键字的被引用的 (/reference) 标识符。