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

  • Thread starter Thread starter Jason Kendall
  • Start date Start date
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)
 
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 "}}"."
 
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!
 
* 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.
 
Back
Top