about learning and improving skills
Curly braces in C# String.Format()
Ever wanted to use String.Format on, say, a javascript function? Those include curly braces ( { or } ), but those curly braces are reserved as placeholder marker in String.Format() (i.e. for {0}). Escaping the braces with a backslash (comes to mind first in C#) does not work, though.
The solution is pretty simple: You need to double those curly braces to escape them:
String.Format("function test() {{ return calcSomething({0}); }}", "123");
| Print article | This entry was posted by Sebastian on 2010/07/23 at 18:53, and is filed under .NET, Development. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |