Next We call GetTitle() and pass it the html string. The Regex uses Kleene closures to process the text inside matching title tags.
Note The star means "zero or more," and the plus means "one or more." The "\s" indicates whitespace characters.
Dim html as String = "<html><title>Example.</title><body><p>...</p></body></html>"
Function GetTitle(value as String)
' Use regular expression to match title tags.
Dim match as Match = Regex.Match(value, "<title>\s*(.+?)\s*</title>")
Some notes. This code will may work correctly if the html page has commented-out HTML on it. And it won't match uppercase TITLE tags. For case-insensitive code, consider the RegexOptions enum.
It is possible in many cases to match the title element from an HTML page (or a String containing HTML). And this is sufficient for further processing of the data in VB.NET.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.