[C#] Strip HTML from string. - Yin - 04-05-2010
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.
RE: [C#] Strip HTML from string. - Sam - 04-05-2010
If this does what I think it does then you sir are a wise man.
RE: [C#] Strip HTML from string. - RaZoR03 - 04-18-2010
(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
|