可以将参数的格式说明符作为另一个参数传递给 String.Format 吗?
例如,假设我在字符串变量中有 DateTime 格式字符串,.NET 中是否有任何语法或方法可以让我执行与此无效代码等效的操作:
String line = String.Format("{0:{1}}", DateTime.Now, dateTimeFormat);
^^^ ^
| |
+-- this would use this --+
For instance, let's say I have the DateTime format-string in a string variable, is there any syntax or method in .NET that would let me do the equivalent of this invalid code:
String line = String.Format("{0:{1}}", DateTime.Now, dateTimeFormat);
^^^ ^
| |
+-- this would use this --+
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为此语法概述几乎不包括动态参数。
您必须以某种方式使用两阶段系统,要么预先格式化日期,要么生成格式字符串。但我认为两者都会比问题更糟糕。
I think this syntax overview pretty much excludes dynamic parameters.
You will have to use a 2 stage system somehow, either pre-formatting your Date or by generating a format string. But I think both will be worse than the problem.
只是有什么问题吗
?
What's wrong with just
?