How can brackets be escaped in using string.Format
. For example:
String val = "1,2,3"
String.Format(" foo {{0}}", val);
This example doesn't throw an exception, but outputs the string foo {0}
Is there a way to escape the brackets?
How can brackets be escaped in using string.Format
. For example:
String val = "1,2,3"
String.Format(" foo {{0}}", val);
This example doesn't throw an exception, but outputs the string foo {0}
Is there a way to escape the brackets?
Escaping curly brackets AND using string interpolation makes for an interesting challenge. You need to use quadruple brackets to escape the string interpolation parsing and
string.format
parsing.Escaping Brackets: String Interpolation $("") and String.Format
You can use double open brackets and double closing brackets which will only show one bracket on your page.
For you to output
foo {1, 2, 3}
you have to do something like:To output a
{
you use{{
and to output a}
you use}}
.