How to put unprocessed (escaped) words inside String.Format

前端 未结 4 1338
我寻月下人不归
我寻月下人不归 2020-12-30 21:15

I am formatting a date:

str = String.Format(\"{0:MMM d m:mm\"+yearStr+\"}\", dt);

I want to put the word \"at\" after the \"d\", but I don\

4条回答
  •  攒了一身酷
    2020-12-30 21:42

    Just for fun, but works.

    var what=new object[] { "{{{{0:MMM d}}}} {0} {{{{0:m:mm:{{0}}}}}}", "at", yearStr, dt };
    var that=what.Aggregate((a, b) => String.Format((String)a, b));
    

    You can merge two lines in one. The at which you want to put between two formats is also parameterized.

提交回复
热议问题