Solarion
Honorary Master
- Joined
- Nov 14, 2012
- Messages
- 21,886
I have a form which I allows someone to compile an email in a Textbox. It must include carriage returns. I am trying to use this to encode the textbox into an html format.
The bold bit is where I'm having a problem. I have added a reference to the System.Web as well. It still will not allow me to use HttpUtility.
Just to add, if anyone knows of a quicker way to achieve what I'm trying to do then I am all ears!
Code:
Imports System.Net
Imports System.Web
Code:
Public Function ToHtml(s As String, nofollow As Boolean) As String
s = [B]HttpUtility[/B].HtmlEncode(s)
Dim paragraphs As String() = s.Split(New String() {vbCr & vbLf & vbCr & vbLf}, StringSplitOptions.None)
Dim sb As New StringBuilder()
For Each par As String In paragraphs
sb.AppendLine("<p>")
Dim p As String = par.Replace(Environment.NewLine, "<br />" & vbCr & vbLf)
If nofollow Then
p = Regex.Replace(p, "\[\[(.+)\]\[(.+)\]\]", "<a href=""$2"" rel=""nofollow"">$1</a>")
p = Regex.Replace(p, "\[\[(.+)\]\]", "<a href=""$1"" rel=""nofollow"">$1</a>")
Else
p = Regex.Replace(p, "\[\[(.+)\]\[(.+)\]\]", "<a href=""$2"">$1</a>")
p = Regex.Replace(p, "\[\[(.+)\]\]", "<a href=""$1"">$1</a>")
sb.AppendLine(p)
End If
sb.AppendLine("</p>")
Next
Return sb.ToString()
End Function
The bold bit is where I'm having a problem. I have added a reference to the System.Web as well. It still will not allow me to use HttpUtility.
Just to add, if anyone knows of a quicker way to achieve what I'm trying to do then I am all ears!