Add a method to an object
Posted on 2007-11-26
I want to add a custom method to an object, I have a function called Sanitize, this takes a string and sanitises it for SQL, currently I would call it like so:
dim str as string
str = "a 'little' form"
str = Sanitize(str)
What I would lke ot be able to do is add the function Sanitize to the string object, so to clean a string I would just type:
How do I do this, and can yo upllease provide the correct terms for this process too?
For info, this is my Sanitize function
Public Shared Function Sanitize(ByVal str as String) As String
str = Replace(str, "'", "''")
str = Replace(str, Chr(34), Chr(34) & Chr(34))
str = HttpUtility.HtmlEncode(str)
str = str.Replace(Environment.NewLine, "<br />")
Sanitize = str