How to escape braces (curly brackets) in a format string in .NET

后端 未结 10 2348
不思量自难忘°
不思量自难忘° 2020-11-22 02:44

How can brackets be escaped in using string.Format.

For example:

String val = \"1,2,3\"
String.Format(\" foo {{0}}\", val); 

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 03:35

    Almost there! The escape sequence for a brace is {{ or }} so for your example you would use:

    string t = "1, 2, 3";
    string v = String.Format(" foo {{{0}}}", t);
    

提交回复
热议问题