0

I am looking for a text editor for my asp.net mvc project. I was able to find a lot of text editor out there works pretty well.

What I am looking for is a editor that accept only regualr character like "I am a superman". I do not want to save "<p><strong>I am a superman</strong></p>" into my SQL table since I have to show it thru textbox(example : <%= Html.TextBox("Remark", Model.empExperience.Remark)%>).

Let me know.

1
  • This is what I did. public string StripTags(string strHTML) { if (string.IsNullOrEmpty(strHTML)) return string.Empty; // Removes tags from passed HTML strHTML = HttpUtility.HtmlDecode(strHTML); strHTML = Regex.Replace(strHTML, @"<(.|\n)*?>", string.Empty); return strHTML; } Commented Sep 16, 2010 at 13:39

2 Answers 2

2

Seeing as you do not wish to allow HTML, your best bet is to simply have a means of stripping HTML from the provided input. There's no need to implement a custom text editor for this sort of thing.

Have a look at: How can I strip HTML tags from a string in ASP.NET?

Sign up to request clarification or add additional context in comments.

3 Comments

Your answer sounds right, but it looks complicate to use "<[^>]*>". Let's say there is a HTML string "&lt;p&gt;I worked.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;". How do you convert it to "I worked" by using "<[^>]*>"? I tried with many sample code from the link that you provided, but I could not make it work.
If that's your string, you would have to decode it first, e.g. HttpUtility.HtmlDecode(myHtmlEncodedString) before using the RegEx
I did HttpUtility.HtmlDecode(myHtmlEncodedString) and I also Iadded Regex.Replace(myHtmlEncodedString, @"<(.|\n)*?>", string.Empty). It worked out. Thanks Nathan and JustineStolle
1

This is how you do it (to sum up the answers on the link Nathan provided):

    private static readonly Regex StripHtml = new Regex("<[^>]*>", RegexOptions.Compiled);

    /// <summary>
    ///     Strips all HTML tags from the specified string.
    /// </summary>
    /// <param name = "html">The string containing HTML</param>
    /// <returns>A string without HTML tags</returns>
    public static string StripHtmlTags(string html)
    {
        if (string.IsNullOrEmpty(html))
            return string.Empty;

        return StripHtml.Replace(html, string.Empty);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.