Monday, May 6, 2013

Convert text to HTML or HTML to text in asp.net C# VB

 You can use below code to show as HTML in web page  and save in database as text.

   public static string ConvertToHTML(string HtmlText)
        {
            HtmlText = HtmlText.Replace("\r\n", "\r");
            HtmlText = HtmlText.Replace("\n", "\r");
            HtmlText = HtmlText.Replace("\r\r", "<p>");
            HtmlText = HtmlText.Replace("\r", "<br>");
            return HtmlText;
        }
        public static string ConvertHTMLtoText(string HtmlText)
        {
          
            HtmlText = HtmlText.Replace ("\r","\n");
            HtmlText = HtmlText.Replace( "<p>","\r\r");
            HtmlText = HtmlText.Replace( "<br>","\r");
            HtmlText = HtmlText.Replace("\r", "\r\n");
            return HtmlText;
        }