string.Format with { some text }

by Jacobus Meintjes November 27, 2009 14:06

 

Trying to format a string containing a bracket {

1:
string id = "txtId";
   2:  StringBuilder sb = new StringBuilder();
   3:   
   4:  //Formatting this line, would give error: Input string was not in a correct format.
   5:  sb.AppendFormat("$("{0}").click(function () { ", id);
   6:   
   7:  sb.Append("$(this).slideUp();");
   8:  sb.Append("});");



The fix
   1:  string id = "txtId";            
   2:  StringBuilder sb = new StringBuilder();
   3:   
   4:  //Adding another bracket, will do the trick
   5:  sb.AppendFormat("$("{0}").click(function () {{ ", id);
   6:   
   7:  sb.Append("$(this).slideUp();");
   8:  sb.Append("});");

 

Tags:

C#

Comments are closed

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen | Modified by Mooglegiant

About Me

Jacobus Meintjes
 
C# developer working with ASP.Net and/or Windows Forms.
Email Me

Cumulus

This will be shown to users with no Flash or Javascript.

Widget Twitter not found.

Root element is missing.X