Welcome to AspAdvice Sign in | Join | Help

Use String.Format instead of Chopping Strings

Here is a quick example of why string.Format is just so cool

Here is a quick example of why string.Format is just so cool

For example: 

  • text1.Text = string.Format("<a href=\"Mylink.aspx?abc=0&Color={0}\">my Link text</a>", myColor);

Isn't that much nicer than

  • text1.Text = "<a href=\"Mylink.aspx?abc=0&Color=" + myColor + "\">my Link text</a>", myColor);

Now with two parameters it's still so clean!

  •  text1.Text = string.Format("<a href=\"Mylink.aspx?abc=0&ID={0}&wl={1}\">my Link text</a>", myColor, myWeight);
Sponsor
Published Tuesday, May 15, 2007 2:49 PM by salibhai
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below