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

前端 未结 4 1341
我寻月下人不归
我寻月下人不归 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:37

    You can surround literal strings with quotes, which for longer strings is probably easier and a bit more readable than escaping every character with a backslash:

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

    See Custom Date and Time Format Strings in MSDN Library (search for "Literal string delimiter").

    (And did you mean h:mm instead of m:mm?)

提交回复
热议问题