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

J

Jason Kendall

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
(e-mail address removed)
 
S

Sven Groot

Jason said:
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 "}}"."
 
J

Jason Kendall

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!
 
H

Herfried K. Wagner [MVP]

* Jason Kendall said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top