Reputation: 3891
Can we do a String.Format in a string that contains the '{' character?
Example: String.Format("a{a}a {0} bbb {1}", "val1", "val2");
The a{a}a should be interpreted as part of the string, not as a formatter...
Thanks in advance
Upvotes: 4
Views: 4511
Reputation: 78840
Yes. Use two {
s, like this:
String.Format("a{{a}}a {0} bbb {1}", "val1", "val2");
Upvotes: 12
Reputation: 241641
Use: {{
. By the way, this is answerable from the documentation:
To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "
{{
" or "}}
".
Upvotes: 12