using System.Text; using System.Text.RegularExpressions; public class TextHelper { public static string ToText(string htmlStr) { // Its better to use StringBuilder, but it does not support Regular Expression Replacing, so ended up with string class string str = htmlStr; Regex re; string[] arr1 = { "<br />", "<br>", "<hr>", "<hr />", "</p>", "</td><td>", "</tr>", "</td>", "<([^<])*>", " ", "<", ">", "&", """, ""}; string[] arr2 = { "\n", "\n", "\n", "\n", "\n", "\t", "\n", " ", "", " ", "<", ">", "&", "\"", "-"}; for(int i=0; i < arr1.Length; i++) { re = new Regex(arr1[i], RegexOptions.IgnoreCase | RegexOptions.Compiled); str = re.Replace(str, arr2[i]); } return str; } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|