By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,520 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,520 IT Pros & Developers. It's quick & easy.

How do I use a curly brace within a string passed to String.Format?

P: n/a
How do I use a curly brace within a string passed to String.Format?
I want to pass a string that includes a curly brace, but that curly
brace is not being used to indicate a replacable format parameter.

Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}",
Date.Now)

Thanks.

-Jason Kendall
Ja**********@hotmail.com
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jason Kendall wrote:
How do I use a curly brace within a string passed to String.Format?
I want to pass a string that includes a curly brace, but that curly
brace is not being used to indicate a replacable format parameter.

Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}",
Date.Now)


From the docs for String.Format:
"To specify a single literal brace character in format, specify two leading
or trailing brace characters; that is, "{{" or "}}"."

--
Sven Groot

http://unforgiven.bloghorn.com

Nov 20 '05 #2

P: n/a
I know your first thought must have been "Jeez! RTFM."
Let me assure you that I did, but didn't see this reference. I shall
now go back and see what I missed.

Thanks!

On Wed, 19 May 2004 19:18:43 +0200, "Sven Groot" <sv*******@gmx.net>
wrote:
Jason Kendall wrote:
How do I use a curly brace within a string passed to String.Format?
I want to pass a string that includes a curly brace, but that curly
brace is not being used to indicate a replacable format parameter.

Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}",
Date.Now)


From the docs for String.Format:
"To specify a single literal brace character in format, specify two leading
or trailing brace characters; that is, "{{" or "}}"."


Nov 20 '05 #3

P: n/a
* Jason Kendall <Ja**********@hotmail.com> scripsit:
How do I use a curly brace within a string passed to String.Format?
I want to pass a string that includes a curly brace, but that curly
brace is not being used to indicate a replacable format parameter.

Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}",
Date.Now)


Enter "String.Format", place the caret on "Format" and press F1. Select
one of the overloaded versions of this method (for example, the fist in
the list) and read the documentation.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

P: n/a
Jason,
Its not obvious where {{ & }} are documented...

A good reference on what is allowed in String.Format & other format
parameters is:

http://msdn.microsoft.com/library/de...ttingtypes.asp

For {{ & }} specifically:

http://msdn.microsoft.com/library/de...formatting.asp

The first link includes numeric, DateTime, Enumeration & customizing...

Hope this helps
Jay

"Jason Kendall" <Ja**********@hotmail.com> wrote in message
news:dv********************************@4ax.com...
I know your first thought must have been "Jeez! RTFM."
Let me assure you that I did, but didn't see this reference. I shall
now go back and see what I missed.

Thanks!

On Wed, 19 May 2004 19:18:43 +0200, "Sven Groot" <sv*******@gmx.net>
wrote:
Jason Kendall wrote:
How do I use a curly brace within a string passed to String.Format?
I want to pass a string that includes a curly brace, but that curly
brace is not being used to indicate a replacable format parameter.

Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}",
Date.Now)


From the docs for String.Format:
"To specify a single literal brace character in format, specify two leadingor trailing brace characters; that is, "{{" or "}}"."

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.