相关疑难解决方法(0)

如何在.NET中的格式字符串中转义大括号(花括号)

如何在使用中转义括号string.Format.例如:

String val = "1,2,3"
String.Format(" foo {{0}}", val); 
Run Code Online (Sandbox Code Playgroud)

此示例不会抛出异常,但会输出字符串 foo {0}

有没有办法摆脱括号?

.net c# string formatting parsing

954
推荐指数
7
解决办法
27万
查看次数

在String.Format中转义大括号'{'

使用String.Format方法时如何显示文字大括号字符?

例:

sb.AppendLine(String.Format("public {0} {1} { get; private set; }", 
prop.Type, prop.Name));
Run Code Online (Sandbox Code Playgroud)

我希望输出看起来像这样:

public Int32 MyProperty { get; private set; }
Run Code Online (Sandbox Code Playgroud)

.net c# string

890
推荐指数
1
解决办法
20万
查看次数

标签 统计

.net ×2

c# ×2

string ×2

formatting ×1

parsing ×1