c# - Backslash using for escaping qute regenerate after asigning String -
in tostring methode of entity, try generate informational string includes quotes. use backslash before quote , until try assign return value string variable , after backslash comeback .here tostring function:
public override string tostring() { string content = "{"; content += "\"servicetype\":" + servicetype.name + ","; content += "\"debt\":" + amount; content += "}"; return content; } after try use stringwriter , htmltextwriter generate html after assign return value string variable there lot of \, \r, \n, \tin variable.here function:
public string tohtmlstring() { stringwriter stringwriter = new stringwriter(); using (htmltextwriter writer = new htmltextwriter(stringwriter)) { writer.addstyleattribute(htmltextwriterstyle.width, "100%"); writer.addstyleattribute(htmltextwriterstyle.borderstyle, "1px solid black"); writer.addstyleattribute(htmltextwriterstyle.direction, "rtl"); writer.renderbegintag(htmltextwritertag.table);// begin table writer.renderbegintag(htmltextwritertag.tr); writer.renderbegintag(htmltextwritertag.td); writer.write("زیر خدمت"); writer.renderendtag(); writer.renderbegintag(htmltextwritertag.td); writer.write(servicetype.name); writer.renderendtag(); writer.renderendtag(); writer.renderbegintag(htmltextwritertag.tr); writer.renderbegintag(htmltextwritertag.td); writer.write("مبلغ"); writer.renderendtag(); writer.renderbegintag(htmltextwritertag.td); writer.write(amount); writer.renderendtag(); writer.renderendtag(); writer.renderendtag();// end table } return stringwriter.tostring(); } and after assigning value variable:
<table style=\"width:100%;border-style:1px solid black;direction:rtl;\">\r\n\t<tr>\r\n\t\t<td>زیر خدمت</td><td>درمان</td>\r\n\t</tr><tr>\r\n\t\t<td>مبلغ</td><td>6000</td>\r\n\t</tr>\r\n</table> what's happening here?
that result seems ok use in webbrowser control inside c#. if prefer avoid these newlines , tabs (for real browser), can try replacing few lines of code this.
old code:
using (htmltextwriter writer = new htmltextwriter(stringwriter)) { new code:
using (htmltextwriter writer = new htmltextwriter(stringwriter, string.empty)) { writer.newline = string.empty; the second parameter in htmltextwriter string used tab. result like:
<table style=\"width:100%;border-style:1px solid black;direction:rtl;\"><tr><td>زیر خدمت</td><td>درمان</td></tr><tr><td>مبلغ</td><td>6000</td></tr></table> edit: in order avoid \" use <? php echo or <%=(for asp), or better rework result as:
return stringwriter.tostring().replace("\"", "'");
Comments
Post a Comment