c# - 在字符串 : "Input string was not in a correct format" 中使用括号时

标签 c# string c#-4.0 string-formatting

<分区>

如何在 C# 中格式化模式中包含方括号的字符串?当我运行以下语句时...

String.Format("Foo { Bar={0} }", this.Bar);

...我收到一个运行时异常:

System.FormatException: Input string was not in a correct format.

我应该转义括号吗?怎么办?

最佳答案

通过加倍括号来转义括号,例如 {{}}

String.Format("Foo {{ Bar={0} }}", this.Bar);

关于c# - 在字符串 : "Input string was not in a correct format" 中使用括号时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14856648/

相关文章:

c# - 从 RadTimePicker c# 获取输入的时间

c# - Task.ContinueWith() 父任务不等待子任务完成

c# - 尝试概括身份验证(包括参数更改)

php - 如何在 PHP 中查找字符串的所有子字符串

string - 根据动态模式匹配符号流

ruby - rails 中 link_to 描述中的条件

c# - 如何从 Parallel.ForEach 收集返回值?

asp.net-mvc - Linq/Entity Group 然后计算这些组

c# - WPF TabControl 启动时没有选定的项目

c# - 微软 MVC : Is there a way to separate C# code from markup in MVC views?