Tuesday, June 19, 2012

A digit in double curly brackets ends up in single curly brackets on the other side a of String.Format manipulation in C#.

string foo = "The {0} red {1} jumps {2} the {{0}} {{1}} dog.";
string bar = String.Format(foo, "quick", "fox", "over");
string baz = String.Format(bar, "lazy", "brown");

 
 

The variables instantiated above will end up with the following values:

fooThe {0} red {1} jumps {2} the {{0}} {{1}} dog.
barThe quick red fox jumps over the {0} {1} dog.
bazThe quick red fox jumps over the lazy brown dog.

No comments:

Post a Comment