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.