Escaping a { into a format string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Mason

    #1

    Escaping a { into a format string

    Pretty simple question here.

    If I do a format and I want to incluide a { or a } how do I go about it. It
    seems you can't eacape it with a backslash.

    Sofar all I have done is string.Format(" {0}","{"); Is there a better way?

    Thanks
    Ralph




  • Jon Skeet

    #2
    Re: Escaping a { into a format string

    A <aaroraSPAM@ony xREMfund.com> wrote:[color=blue][color=green]
    > > If I do a format and I want to incluide a { or a } how do I go about it.[/color]
    > It[color=green]
    > > seems you can't eacape it with a backslash.[/color]
    >
    > You can also do:
    > string s = @"{0}";[/color]

    That won't help. The @ only makes a difference at compile-time, and the
    compiler doesn't care about { or } in a string.

    For instance:

    Console.WriteLi ne ("{0}", 1);
    is the same as
    Console.WriteLi ne (@"{0}", 1);

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...