I'm trying to ensure that all characters which are not numeric, or alphabetic are converted to HTML code when submitted to my database.
With a bit of Googling, I have come up with this:
Public Shared Function HTMLEncodeSpecialChars(text As String) As String
Dim sb As New System.Text.StringBuilder()
Dim i As Integer
Dim charArray() As Char = text.ToCharArray()
' display contents of charArray
For i = 0 To charArray.Length - 1
sb.Append((String.Format("&#{0};", Asc(charArray(i)))) & ",")
Next
Return sb.ToString()
End Function
This successfully converts anything to HTML, but now I need to put some condition in there so it only does it where I need it to. ie; on any character which will either screw up my database entry, or screw up formatting when returned back to the screen as HTML (this database content is for product data for a website).
So for simplicity, I guess I want to convert only charcters which are not A-Z alphabetic or 1-0 numeric.
I could use isNumeric, but not sure how to detect alphabetic characters.
I've been Googling and found something which looked like it would work, but the logic/filtering was wrong.
So I figured I'd ask here :D