Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#] Strip HTML from string.
#1
Code:
///<summary>
///method to strip HTML tags from a string
///</summary>
///<param name="str">the string to strip</param>
///<returns></returns>
///<remarks></remarks>
public string StripHTML(string str)
{
    try
    {
        int start = 0;
        int end = 0;
        int count = 0;

        while (((str.IndexOf("<") > -1) && (str.IndexOf(">") > -1) && (str.IndexOf("<") < str.IndexOf(">"))))
        {
            start = str.IndexOf("<");
            end = str.IndexOf(">");
            count = end - start + 1;

            str = str.Remove(start, count);
        }

        str = str.Replace(" ", " ");
        str = str.Replace(">", "");
        str = str.Replace("\r\n", "");

        return str.Trim();
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

Enjoy.
Reply
#2
If this does what I think it does then you sir are a wise man.
Reply
#3
(04-05-2010, 05:43 PM)Yin Wrote:
Code:
///<summary>
///method to strip HTML tags from a string
///</summary>
///<param name="str">the string to strip</param>
///<returns></returns>
///<remarks></remarks>
public string StripHTML(string str)
{
    try
    {
        int start = 0;
        int end = 0;
        int count = 0;

        while (((str.IndexOf("<") > -1) && (str.IndexOf(">") > -1) && (str.IndexOf("<") < str.IndexOf(">"))))
        {
            start = str.IndexOf("<");
            end = str.IndexOf(">");
            count = end - start + 1;

            str = str.Remove(start, count);
        }

        str = str.Replace(" ", " ");
        str = str.Replace(">", "");
        str = str.Replace("\r\n", "");

        return str.Trim();
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

Enjoy.

Nice dude,thanks
[Image: 20r9vh4.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Encrypt String using x509Certificate private Key wih RSA jeffstan 0 2,438 01-26-2014, 04:18 PM
Last Post: jeffstan
  HTML Grabber v1 BreShiE 18 6,263 09-28-2012, 01:15 AM
Last Post: rqmok
  Combination Cracker - String Variant Builder - Developed by AceInfinity AceInfinity 0 1,354 03-15-2012, 06:05 PM
Last Post: AceInfinity
  String MD5 Hasher (Coded by Ace) AceInfinity 20 7,382 10-10-2011, 11:57 AM
Last Post: Greyersting
  [Source] TripleDES String Encryption / Decryption euverve 2 3,362 05-13-2011, 10:35 AM
Last Post: Imports System.Net

Forum Jump:


Users browsing this thread: 1 Guest(s)