Remove Links From A String (Or Web Page) with vb.net

Good Morning! Last night my daughter totally kicked but at volleyball. She rocked. She really does has potential to be good at this game. As for me, I wrote code to produce a template class for work, where many of the classes generated follow a similar pattern. It was easier to do it this way than to type out the class by hand which had been done previously. Just insane no doubt about it.

Today’s topic requires one line of code! That’s right just one line. Lets say you have downloaded a web page and you want to remove the links from the string but leave the text of the link behind. This little regular expression will do the trick! Don’t forget to import System.RegularExpressions! Make it a great day!

Imports System.Text.RegularExpressions

System.Text.RegularExpressions.Regex.Replace(yourstring, "</?a[^>]*>", String.Empty)


Join me on Facebook

Technorati Tags: ,,,,,,,,,,,,,,,,,,,

Advertisements
  1. #1 by William Coffey on December 19, 2012 - 11:43 am

    I saw your code on creating a header in Word with VB.net. However, I am having difficulty using different first page and then seeing the header on all the other pages. Here is your code modified slightly.
    ‘first lets get to the header of the document
    oDoc.Content.Application.ActiveWindow.ActivePane.View.SeekView = CInt(Word.WdSeekView.wdSeekCurrentPageHeader)
    ‘Typing something in the header
    oDoc.Content.Application.Selection.TypeText(Text:=”Martens ” & vbCrLf & “page “)
    ‘adding the page contents to the header
    oDoc.Content.Application.Selection.Fields.Add(Range:=oDoc.Content.Application.Selection.Range, Type:=CInt(Word.WdFieldType.wdFieldEmpty), Text:=”page”)
    oDoc.Content.Application.Selection.TypeText(Text:=” of “)
    oDoc.Content.Application.Selection.Fields.Add(Range:=oDoc.Content.Application.Selection.Range, Type:=CInt(Word.WdFieldType.wdFieldNumPages), Text:=”page”)

    • #2 by Kelly's Chronicles on December 19, 2012 - 3:21 pm

      I approved but I think you submitted your comment on the wrong entry. good stuff though.

  2. #3 by Josh on December 11, 2013 - 5:21 am

    As a Fan and a Studen, I wanted to say Many Thanks for your Awesome Work! I never had a chance to this awesome Webpage and to Thank you in person! And here I am. I was working with one of your awesome Projects to get “Window Titles” and “Win Handle”! The code was not complete, so I had to later Create a Smaller Tool by using your Methods, and later posted on VBForums Code Bank with Credits to you. Once again, Many Thanks for your inspirational work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: