PC Review


Reply
Thread Tools Rate Thread

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

 
 
Jason Kendall
Guest
Posts: n/a
 
      19th May 2004
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 Removed)
 
Reply With Quote
 
 
 
 
Sven Groot
Guest
Posts: n/a
 
      19th May 2004
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

 
Reply With Quote
 
Jason Kendall
Guest
Posts: n/a
 
      19th May 2004
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" <(E-Mail Removed)>
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 "}}"."


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      19th May 2004
* Jason Kendall <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      20th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> 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 "}}"."

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
curly brace {} Karl Townsend Microsoft Excel Discussion 4 25th Feb 2009 12:07 AM
How to make string align by string.Format() in CJK? Dancefire Microsoft Dot NET Framework 4 15th Nov 2007 05:48 PM
Curly Brace on 2-lines: How to? =?Utf-8?B?cGVuY2lsaW5l?= Microsoft Word Document Management 1 26th Dec 2005 06:56 PM
Embedded curly brackets in a call to String.Format Chuck Heatherly Microsoft Dot NET Framework 5 25th Feb 2005 04:45 AM
connection string exception : Format of the initialization string does not conform to specification starting at index 0 Gaurav Microsoft ASP .NET 0 7th Nov 2003 10:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 PM.