Cha*_*ley 2 c# string escaping
I have already seen from other answers that to escape the {
or }
char in C# string.Format()
you use {{
or }}
.
But what I need to do is format a string that looks like this:
{{tag}}
Run Code Online (Sandbox Code Playgroud)
However, when I try to escape the double curly braces like this:
string.Format("{{{0}}}", "tag");
Run Code Online (Sandbox Code Playgroud)
or this:
string.Format("{{{{{0}}}}}", "tag");
Run Code Online (Sandbox Code Playgroud)
The output is always this:
{tag}
Run Code Online (Sandbox Code Playgroud)
A different way I have found that works is:
StringBuilder output = new StringBuilder();
output.Append("{{");
output.Append("tag");
output.Append("}}");
Run Code Online (Sandbox Code Playgroud)
But it seems silly to have to have all that just to format a string.
Am I missing something obvious?
In order to do this you need 5 braces on either side of the expression
Console.WriteLine("{{{{{0}}}}}", "tag");
Run Code Online (Sandbox Code Playgroud)
The break down is
{
{
{
in {0}