Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can get plain text from Ajax editor


When i use the following mathod i m getting


C#
public static class StringHelpers
{
    public static string StripHTML(this string HTMLCode)
    {
        //var reg = new Regex("<[^>]+><", RegexOptions.IgnoreCase);
        //return reg.Replace(HTMLText, "");
        // Remove new lines since they are not visible in HTML
        HTMLCode = HTMLCode.Replace("\n", " ");

        // Remove tab spaces
        HTMLCode = HTMLCode.Replace("\t", " ");

        // Remove multiple white spaces from HTML
        HTMLCode = Regex.Replace(HTMLCode, "\\s+", " ");

        // Remove HEAD tag
        HTMLCode = Regex.Replace(HTMLCode, "<head.*?", ""
                            , RegexOptions.IgnoreCase | RegexOptions.Singleline);

        // Remove any JavaScript
        HTMLCode = Regex.Replace(HTMLCode, "<script.*?", ""
          , RegexOptions.IgnoreCase | RegexOptions.Singleline);

        // Replace special characters like &, <, >, " etc.
        System.Text.StringBuilder sbHTML = new System.Text.StringBuilder(HTMLCode);
        // Note: There are many more special characters, these are just
        // most common. You can add new characters in this arrays if needed
        string[] OldWords = {" ", "&", """, "<",
   ">", "®", "©", "", ""};
        string[] NewWords = { " ", "&", "\"", "<", ">", "®", "©", "•", "™" };
        for (int i = 0; i < OldWords.Length; i++)
        {
            sbHTML.Replace(OldWords[i], NewWords[i]);
        }

        // Check if there are line breaks (<br>) or paragraph (<p>)
        sbHTML.Replace("<br>", "\n<br>");
        sbHTML.Replace("<br hold=" />        sbHTML.Replace("><p hold=" /><br mode="><[^>]*>", "");
       return System.Text.RegularExpressions.Regex.Replace(
        sbHTML.ToString(), "<[^>]*>", "");
     
     
       

    }
}



the out put become
(IT TAKE ALONG WITH EDITOR INFORMATION IN START AND LATER PROPER TEXT INFORMATION)

as

(first in comes)

Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable{mso-style-name:"Table Normal";mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-priority:99;mso-style-parent:"";mso-padding-alt:0in 5.4pt 0in 5.4pt;mso-para-margin-top:0in;mso-para-margin-right:0in;mso-para-margin-bottom:10.0pt;mso-para-margin-left:0in;line-height:115%;mso-pagination:widow-orphan;font-size:11.0pt;font-family:"Calibri","sans-serif";mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:"Times New Roman";mso-bidi-theme-font:minor-bidi;}


(Text start from here)
The MirasInternational School, Astana (is the member of the NursultanNazarbayev Educational Foundation) was formally opened on September 2,1999 as a private educational institution offering a curriculumbased on the Kazakh National Curriculum and the InternationalBaccalaureate (IB) Programmes.In 2004 we made a great achievement, becoming the only theschool in Kazakhstan accredited by the New England Associationof the Schools and Colleges (NEASC),the Council of International Schools (CIS) and authorized by the International Baccalaureatefor three IB Programmes (PYP, MYP and DP). The Schoolprovides a holistic, stimulating, balanced and challenging education. Theprograms follow three stages: Kindergarten to Grade 5; Grades 6–10, Grade11.


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 15-Mar-12 22:03pm
v2
Comments
BobJanova 16-Mar-12 5:41am    
Does it not have a PlainText property or similar? Or, uh, why not just use a <textarea> if you just want the plain text ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900