trying to build a string with stringbuilder fails

  • Thread starter Thread starter Carlos
  • Start date Start date
C

Carlos

Hi,

I've tried to build a htm string using stringbuilder, but having
a problem when using double quotes (") as values. I use the
escape char (\), but it still reports an error. i.e.the
following does not compile:

sb.Append("<TABLE id=\"Table5\" style=\"Z-INDEX: 102; LEFT: 25%; WIDTH: 70%;
POSITION: absolute; TOP: 220px; HEIGHT: 100%\" cellSpacing=\"1\"
cellPadding=\"1\" border=\"0\"><TR><TD align=\"center\" style=\"width:
619px\"><TABLE id=\"HeadATC\" style=\"WIDTH: 100%; HEIGHT: 44px\"
borderColor=\"#000080\" cellSpacing=\"1\" cellPadding=\"7\" rules=\"none\"
bgColor=\"#ffffe0\" border=\"1\" frame=\"box\" runat=\"server\"><TR><TD
align=\"center\" bgColor=\"Gainsboro\"><FONT face=\"Arial, Helvetica, Helv\"
color=\"#00008b\" size=\"4\"><B> <span style=\"font-size: 12pt; color:
#000080\">ATC</span></B></FONT></TD></TR> </TABLE></TD></TR></TABLE>")

Thanks!
 
Hi,

I've tried to build a htm string using stringbuilder, but having
a problem when using double quotes (") as values. I use the
escape char (\), but it still reports an error. i.e.the
following does not compile:

sb.Append("<TABLE id=\"Table5\" style=\"Z-INDEX: 102; LEFT: 25%; WIDTH: 70%;
POSITION: absolute; TOP: 220px; HEIGHT: 100%\" cellSpacing=\"1\"
cellPadding=\"1\" border=\"0\"><TR><TD align=\"center\" style=\"width:
619px\"><TABLE id=\"HeadATC\" style=\"WIDTH: 100%; HEIGHT: 44px\"
borderColor=\"#000080\" cellSpacing=\"1\" cellPadding=\"7\" rules=\"none\"
bgColor=\"#ffffe0\" border=\"1\" frame=\"box\" runat=\"server\"><TR><TD
align=\"center\" bgColor=\"Gainsboro\"><FONT face=\"Arial, Helvetica, Helv\"
color=\"#00008b\" size=\"4\"><B> <span style=\"font-size: 12pt; color:
#000080\">ATC</span></B></FONT></TD></TR> </TABLE></TD></TR></TABLE>")

It works for me. I'm assuming that your actual code doesn't contain
line breaks and that the statement is terminated with a semi-colon.

GEJ
 
Works for me too

StringBuilder sb = new StringBuilder();
sb.Append("<TABLE id=\"Table5\" style=\"Z-INDEX: 102; LEFT: 25%; WIDTH:
70%;POSITION: absolute; TOP: 220px; HEIGHT: 100%\" cellSpacing=\"1\"
cellPadding=\"1\" border=\"0\"><TR><TD align=\"center\" style=\"width:
619px\"><TABLE id=\"HeadATC\" style=\"WIDTH: 100%; HEIGHT: 44px\"
borderColor=\"#000080\" cellSpacing=\"1\" cellPadding=\"7\" rules=\"none\"
bgColor=\"#ffffe0\" border=\"1\" frame=\"box\" runat=\"server\"><TR><TD
align=\"center\" bgColor=\"Gainsboro\"><FONT face=\"Arial, Helvetica, Helv\"
color=\"#00008b\" size=\"4\"><B> <span style=\"font-size: 12pt; color:
#000080\">ATC</span></B></FONT></TD></TR> </TABLE></TD></TR></TABLE>");

Response.Write(sb.ToString());


-NitRaGs
 
Thank you all for your response. However since the code is not in C#,
bu in VB, It would not work. I figured out finally.. I had to use single
quotes (')
instead of double (")...

Thnaks again
 
Back
Top