如何把未经处理(逃)内的String.Format话String、Format

2023-09-03 06:22:03 作者:鸢

我格式化日期:

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

我希望把这个词的的D后,但我不希望字符串格式化。我只是想单词在。

I want to put the word "at" after the "d", but I don't want the string to format it. I just want the word "at".

我怎样才能做到这一点?

How can I achieve this?

推荐答案

您可以环绕文字字符串加上引号,这对长字符串可能是更容易,有点更具可读性比转义每一个字符用一个反斜杠:

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);

请参阅自定义日期和时间格式字符串在MSDN库(搜索文字字符串分隔符)。

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

(?你的意思是 H:毫米而不是?M:毫米

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