How to avoid input string/StringBuilder in an incorrect format error in C#

c#, string

Solution

This error is possible only with `StringBuilder.AppendFormat` and if your string contains { or }. So the solution is to use `StringBuilder.Append` (as you don`t really use the format part):

content.Append("<td>" + idcStepEntity.Comment + "</td>");

Problem

I'm using a string builder to append text to string. ``` StringBuilder content = new StringBuilder(GetStartHTML("installation",string.Empty)); ....... content.AppendFormat("<td>" + idcStepEntity.Comment + "</td>"); ``` Unfortunetly i cannot control what comes in from the customer as comment, so i they write something like : comment { commment] comment (and they often do) i get string was not in a correct format error. That mean i should not use a StringBuilder here? Should i use`string += otherstring` or is there any other String class that can bu usefull here? Thanks in advance :)

Original source