How do I display a literal curly brace character when using the String.Format method?
Example:
sb.AppendLine(String.Format("public {0} {1} { get; private set; }", prop.Type, prop.Name));
I would like the output to look like this:
public Int32 MyProperty { get; private set; }
Format strings contain “replacement fields” surrounded by curly braces {} . Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }} .
Use "{{ '{' }}") to escape it.)
In languages like C curly braces ( {} ) are used to create program blocks used in flow control. In Python, curly braces are used to define a data structure called a dictionary (a key/value mapping), while white space indentation is used to define program blocks.
The curly braces show where the inserted value should go. You can insert more than one value. The values do not have to be strings, they can be numbers and other Python objects. >>>
Use double braces {{
or }}
so your code becomes:
sb.AppendLine(String.Format("public {0} {1} {{ get; private set; }}", prop.Type, prop.Name)); // For prop.Type of "Foo" and prop.Name of "Bar", the result would be: // public Foo Bar { get; private set; }
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