如何把未经处理(逃)内的String.Format话 [英] How to put unprocessed (escaped) words inside String.Format

查看:134
本文介绍了如何把未经处理(逃)内的String.Format话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我格式化日期:

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

这篇关于如何把未经处理(逃)内的String.Format话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆