Home :
Tutorials
Strip All Html From A String
Added by
David Coleman
on
29 May 2010
Sometimes, such as when you want to show a brief snippet of text in search results, you'll want to strip all of the HTML tags out of a string so that you don't end up with un-finished tags.
This can be simply accomplished with the following line of code (in VB):
yourString = Regex.Replace(yourString,"\<.*?\>", String.Empty)
This code uses a regular expression to find all text in the string between triangle brackets <> and then replaces it with an empty string.
Simples!