HTML converted to plain text, support apostrophe

Source: Internet
Author: User

 /// <summary>        ///HTML conversion to plain text/// </summary>        /// <param name= "source" ></param>        /// <returns></returns>        Private Static stringHtmltoplaintext (stringsource) {            stringresult; //Remove Line Breaks,tabsresult = source. Replace ("\ r"," "); Result= result. Replace ("\ n"," "); Result= result. Replace ("\ t"," "); //Remove the headerresult = Regex.Replace (result,"(",string.            Empty, regexoptions.ignorecase); Result= Regex.Replace (Result,@"< () *script ([^>]) *>","<script>", regexoptions.ignorecase); Result= Regex.Replace (Result,@"(<script>). * (</script>)",string.            Empty, regexoptions.ignorecase); //Remove All Stylesresult = Regex.Replace (result,@"< () *style ([^>]) *>","<style>", regexoptions.ignorecase);//Clearing attributesresult = Regex.Replace (result,"(<style>). * (</style>)",string.            Empty, regexoptions.ignorecase); //Insert tabs in spaces of <td> tagsresult = Regex.Replace (result,@"< () *td ([^>]) *>"," ", regexoptions.ignorecase); //Insert line breaks in places of <br> <li> tagsresult = Regex.Replace (result,@"< () *br () *>","\ r", regexoptions.ignorecase); Result= Regex.Replace (Result,@"< () *li () *>","\ r", regexoptions.ignorecase); //Insert line paragraphs in places of <tr> <p> tagsresult = Regex.Replace (result,@"< () *tr ([^>]) *>","\r\r", regexoptions.ignorecase); Result= Regex.Replace (Result,@"< () *p ([^>]) *>","\r\r", regexoptions.ignorecase); //remove anything thats enclosed inside < >result = Regex.Replace (result,@"<[^>]*>",string.            Empty, regexoptions.ignorecase); //Replace special characters:result = Regex.Replace (result,@"&amp;","&", regexoptions.ignorecase); Result= Regex.Replace (Result,@"&nbsp;"," ", regexoptions.ignorecase); Result= Regex.Replace (Result,@"&lt;","<", regexoptions.ignorecase); Result= Regex.Replace (Result,@"&gt;",">", regexoptions.ignorecase); Result= Regex.Replace (Result,@"& #39;","'", regexoptions.ignorecase); Result= Regex.Replace (Result,@"& (. { 2,6});",string.            Empty, regexoptions.ignorecase); //remove extra line breaks and tabsresult = Regex.Replace (result,@" ( )+"," "); Result= Regex.Replace (Result,"( \ R) () + (\ r)","\r\r"); Result= Regex.Replace (Result,@"(\r\r) +","\ r \ n"); returnresult; }

HTML converted to plain text, support apostrophe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.