Sunday, January 8, 2012

string.format escape sequence in c#

Recently I was working on something and I need to put a curly bracket on the string with a string.format function but I was not aware how to to do it. So I did some search on internet and found how to give escape sequence in string.format. Suppose You need to put curly bracket then you have write two ‘{{‘ instead of { to put ‘{‘ and same way ‘}}’ to put ‘}’

Let’s take simple example. Following is a code where I am printing simple string with string.format and Response.Write.

using System;
using System.Web.UI;

namespace CallBack
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write( string.Format(@"{{ escape sequence for string format from {0}}}", "DotNetJalps"));
        }

    }
}


Now let’s run that example in browser and let’s see how it goes.


C#,Escape Sequence,String.format

That’s it. It’s very easy to use.Hope you liked it. Stay tuned for more..Happy Programming.

Shout it

kick it on DotNetKicks.com
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews