Tuesday, May 3, 2011

How to write content of stringbuilder to a textbox

hi guys, I have a textbox in which i have to write content inside stringbuilder. Following is my stringbuilder.

Dim strString As New StringBuilder()
        strString.AppendLine("<table>")
        strString.AppendLine("<tr><td>")
        strString.AppendLine("<br/><br/>")
        strString.AppendLine("<div style=""text-transform: capitalize;""><strong>Dear " & Session("PatientName") & ",")
        strString.AppendLine("</strong></div></td></tr>")
        strString.AppendLine("<br/><br/>")
        strString.AppendLine("<tr><td>")
        strString.AppendLine("Your appointment has been confirmed.")
        strString.AppendLine("<br /><br />")
        strString.AppendLine("Your appointment Time: " + Session("AppTime"))
        strString.AppendLine("<br />")
        strString.AppendLine("Your appointment Date: " + Session("AppointmentDate"))
        strString.AppendLine("</td></tr>")
        strString.AppendLine("<tr><td>")
        strString.AppendLine("<br/><br/>")
        strString.AppendLine("</table>")

I have used textbox.text=strString.ToString().But in that html tags r also displaying. I want to write above in a textbox.What code i hve to write to remove html tags and i want to write in above given html format?

From stackoverflow
  • This should do it:

    textbox.Text = Regex.Replace(strString.ToString(), _
                             "<(.|\n)*?>", string.Empty)
    
  • Just FYI.

    You could remove the html as per Jose's suggestion but that's not going to preserve the HTML Table layout... you'll just get everything as individual lines. Like wise, you'll have no HTML formatting if you're trying to save this back from the textbox.

    Dead account : Also your HTML is very badly formed.
  • No need for the tags in a textbox, you should do something like the following:

    Dim strString As New StringBuilder()
    strString.AppendLine()
    strString.AppendLine("Dear " & System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Session("PatientName")) & ",")
    strString.AppendLine()
    strString.AppendLine("Your appointment has been confirmed.")
    strString.AppendLine()
    strString.AppendLine("Your appointment Time: " + Session("AppTime"))
    strString.AppendLine("Your appointment Date: " + Session("AppointmentDate"))
    textbox.text = strString.ToString
    

0 comments:

Post a Comment