Escaping a curly braces in String.Format

If you ever recieve the error “Input string was not in correct format.” check the string for curly braces.  Since String.Format uses curley braces to denote the replacement positions you need to escape them.  To do so all you need to do is replace the single curley brace ‘{‘ with a double ‘{{‘.

Bad    – String.Format(“{Somthing To Format ‘{0}’}”, something);
Good – String.Format(“{{Somthing To Format ‘{0}’}}”, something);

Explore posts in the same categories: .NET


You can comment below, or link to this permanent URL from your own site.

7 Comments on “Escaping a curly braces in String.Format”

  1. FNH Says:

    Nice one! This had me going round in circles, thanks for posting. 🙂

  2. Manoj Says:

    Thanks for sharing.! 🙂

  3. Jaco Says:


  4. Manish Says:

    Thanks, this helped!

  5. JD Says:

    Very helpful, thanks for this post!

  6. Anonymous Says:

    Thanks a lot for this straight and accurate post !

  7. Brij Sharma Says:

    Just the right solution of my problem. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: