|
| How do I escape curly braces in a format string? |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.languages.csharp.
| Tony Chow |
....since curly braces already delimit format specifiers.
Say if I want to compose the following client-side javascript with a dynamic value in it:
function IsThisAlright(value) { return value != dynamicnumber; }
.... in which "dynamicnumber" is generated on the server side at runtime.
If I use the String.Format() to construct this script and inserting the dynamic value, how do I escape the curly braces?
This is driving me nuts. I can't local this elementary bit of information in the documentation!
Please help. Thanks in advance.
|
|
|
| |
|
| |
| |
| Greg Ewing |
Tony, you can escape the { and } with a \.
So, you would use Console.WriteLine("This is a curly bracket \{"); to print a left curly.
In your VS.NET IDE help you can find more info at:
ms-help://MS.VSCC/MS.MSDNVS/cpgenref/html/xsdrefsinglecharacterescape.htm
-- Greg http://www.claritycon.com/
"Tony Chow" <Click here to reveal e-mail address> wrote in message news:e$YchNQACHA.1092@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
| |
| |
| -glenn- |
Greg, that doesn't seem to work with String.Format or Console.WriteLine.
The help section you reference is for an XML Schema Regular Expression where I think you can escape curly braces as you can with "regular" Regular Expressions.
-glenn-
"Greg Ewing" <Click here to reveal e-mail address> wrote in message news:#pgp1WQACHA.2284@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Greg Ewing |
glenn, my bad, I wrote the code off the top of my head assuming it would work for Format and WriteLine. Sorry about that. You're {{ }} solution definitely works though.
-- Greg http://www.claritycon.com/
"-glenn-" <Click here to reveal e-mail address> wrote in message news:Org$6LRACHA.1648@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
| |
|
|
|
| |
| -glenn- |
Tony, I couldn't find it in the docs either (read it here about a week ago). I think what you want is to use two braces wherever you need one. For example, if your format string is:
"{{ <{0}> }}"
And you pass "hi" as the first parameter, it will come out as:
{ <hi> }
-glenn-
"Tony Chow" <Click here to reveal e-mail address> wrote in message news:e$YchNQACHA.1092@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|