Strange strings showing up in database.

  • Thread starter Thread starter Vb2Machines
  • Start date Start date
V

Vb2Machines

Hello to all
I have an ASP.NET application that uses VB.NET as the background
language and SQL server 2K as the back end database. I just recently
converted this application from classic asp and I have some erratic behavior
that I can't understand.

Some of the text is being saved and returned in patterns like the following.
&#8729

The constant in all of it is that the string starts with &# and ends with ;
and there is a sequence of numbers contained in the middle. What is it and
is there a better solution that a regular expression to search for the
pattern and replace it? If not does anyone know how to form the string for
the regex that will find it?

Thanks in advance,
Pat
 
They are html character codes and can be fixed like so...



Public Function HTMLDecode(ByVal objText As Object) As String

Dim strTemp As New System.Text.StringBuilder(256)

Dim strExpTab As String

If TypeOf objText Is System.DBNull Then

strTemp.Append(" ")

Else

' Create tab expansion string if not done already

If strExpTab Is Nothing Then

strExpTab = New String(" "c, 4).Replace(" ", " ")

End If

strTemp.Append(HttpUtility.HtmlDecode(objText.ToString()))

'strTemp.Append(HttpUtility.HtmlEncode(objText.ToString()))

strTemp.Replace(" ", "  ") ' Two spaces

strTemp.Replace(ControlChars.Tab, strExpTab)

strTemp.Replace(ControlChars.Cr, "")

strTemp.Replace(ControlChars.Lf, "<br>")

If strTemp.Length = 0 Or (strTemp.Length = 1 And strTemp(0) = " "c) Then

strTemp.Remove(0, strTemp.Length).Append("&nbsp;")

End If

End If

Return strTemp.ToString()



End Function 'HTMLDecode



I borrowed an idea I found elsewhere. that author used the htmlencode method
of the httputitlity.



Thanks,

Pat
 
Back
Top