【问题标题】:system format exception in string.formatstring.format 中的系统格式异常
【发布时间】:2014-03-14 00:51:33
【问题描述】:

我有一个用 c# 编写的 http 服务器,并且我用 c# 编写了一些 html。 我在使用 XmlWiter 编写一些 jQuery 时遇到引号问题。

这个有效

xmlWriter.WriteRaw(@" $(document).ready(function (){  $("".fill-div"").attr(""href"",""Photo by Kelly Clark"");});");

但这不是我想做的事

xmlWriter.WriteRaw(string.Format(@" $(document).ready(function (){  $("".fill-div"").attr(""href"",""{0}"");});", backUrl));

backUrl 是我在 c# 函数中获得的局部变量,我需要将其设置为链接

【问题讨论】:

  • “不起作用”是什么意思?
  • 谢谢。请再次查看问题标题。

标签: c# jquery html xmlwriter string.format


【解决方案1】:

发生错误是因为string.Format 的第一个参数已经有花括号来表示函数。您必须像对引号所做的那样转义大括号:

xmlWriter.WriteRaw(string.Format(@" $(document).ready(function (){{  $("".fill-div"").attr(""href"",""{0}"");}});", backUrl));

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 1970-01-01
    • 2017-08-05
    • 2020-05-16
    • 1970-01-01
    • 2021-12-11
    • 2020-02-01
    • 2017-08-04
    • 1970-01-01
    相关资源
    最近更新 更多