zoukankan      html  css  js  c++  java
  • 当stringFormat碰上{和}

    常常用到stringFormat,在数据绑定时会用<%#DataBinder.Eval(Container.DataItem,"Date","发布时间:{0:yyyy-MM-dd hh:mm}"%>
    在字符串连时string.Format()方法也很方便
    string scriptB = "<script language = \"javascript\">";
    string scriptE = "</script>";

    Page.RegisterClientScriptBlock(ClientID,string.Format(@"{0}
    ......
    {1}
    {0}
    .......
    {1}
    "),scriptB,scriptE);


    可这个好用的东东微软去设计不够完善

    当你的stringFormat语句中本身就有用"{""}"字符,那就麻烦了,本来我想用转义字符"\{"和"\}"
    但这样的语句是错误的:"\{ xxxxx{0}yyyyy \}",那么一碰到"{"我们就不能用stringFormat了吗,解决办法其实很简单:
    string a = "{";

    string b = "}";

    那么你就可以写

    string.Format("function myfun() {0} xxx;yyy;zzz; {1}", a, b);

    问题解决;

    补充:"{{"和"}}"也可以解决此问题,这种感觉有点像SQLServer中的语义。

  • 相关阅读:
    TechRoad_oneStep_0410
    Tech road one step
    TechRoad--oneStep--0327
    TechRoad_oneStep 0313
    Tech road one step
    Tech road one step
    Tech road one step
    Tech road one step
    Tech road one step
    Tech road one step
  • 原文地址:https://www.cnblogs.com/think/p/135418.html
Copyright © 2011-2022 走看看