How to encode html to replace special characters

A simple function that will replace all your html tags into character code great for storing HTML in XML tags:

 

VB Code

Public Function encoder(htmlcode As String) As String 
Dim writer As New IO.StringWriter 
Server.HtmlEncode(htmlcode, writer) 
Dim result As String = writer.ToString 
Return result 
End Function

C# Code

public string encoder(string htmlcode)
{
	System.IO.StringWriter writer = new System.IO.StringWriter();
	Server.HtmlEncode(htmlcode, writer);
	string result = writer.ToString();
	return result;
       //HttpContext.Current.Server.HtmlEncode(htmlcode, writer);
}

Related Posts

No Comments Yet.

Leave a reply

You must be logged in to post a comment.


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /homepages/35/d428352912/htdocs/WilliamMendoza/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048