C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
StripTags: Here all text matching the pattern < followed by multiple characters and ending with > is replaced with an empty string.
Regex.ReplaceMain: We declare a String literal that contains HTML markup. Next, the StripTags function is invoked with that String as the argument.
Finally: We demonstrate that the resulting string has no HTML markup remaining by printing it to the Console.
ConsoleVB.NET program that removes HTML markup from String
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' Input.
Dim html As String = "<p>There was a <b>.NET</b> programmer " +
"and he stripped the <i>HTML</i> tags.</p>"
' Call Function.
Dim tagless As String = StripTags(html)
' Write.
Console.WriteLine(tagless)
End Sub
''' <summary>
''' Strip HTML tags.
''' </summary>
Function StripTags(ByVal html As String) As String
' Remove HTML tags.
Return Regex.Replace(html, "<.*?>", "")
End Function
End Module
Output
There was a .NET programmer and he stripped the HTML tags.
Alternatively: You can build a more advanced parser that handles the incorrect markup you encounter.