How can I format a String in C# where the pattern has brackets? When I run the following statement...
String.Format("Foo { Bar={0} }", this.Bar);
... I receive a runtime exception:
System.FormatException: Input string was not in a correct format.
Should I have to escape the brackets? How to?
Escape the brackets by doubling the brackets like {{
and }}
String.Format("Foo {{ Bar={0} }}", this.Bar);
Try using double curly braces, so it looks like:
String.Format("Foo {{ Bar={0} }}", this.Bar);
Looks like it has already been answered: Escape curly brace '{' in String.Format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With