HREF Tags - to - Text Demo

This demo illustrates how to use regular expressions to convert HREF tags into text tags. The below page is a saved version of the HTML from http://www.asp.net/. Note the "links" on the left hand column, for instance. They are HTML hyperlinks on the ASP.NET page, but here, I have used regular expressions to turn them into text links with the following format: URL Description [URL].


Welcome to the ASP.NET Home Page
 
  Home [http://www.asp.net/default.aspx]
  Newsgroups [http://www.asp.net/newsgroups.aspx]
  Discussions [http://www.asp.net/discussions.aspx]
  Samples [http://www.asp.net/samples.aspx]
  Books [http://www.asp.net/books.aspx]
  Articles [http://www.asp.net/articles.aspx]
  Events [http://www.asp.net/events.aspx]
  FAQ [http://www.asp.net/faq.aspx]
  123aspx.com [http://www.123aspx.com/]
  ASP Next Gen [http://www.aspnextgen.com/]
  ASPFree.com [http://www.aspfree.com/asp+/Default.aspx]
  ASPNG.com [http://www.aspng.com/]
  ASP Today [http://www.asptoday.com/]
  4GuysFromRolla.com [http://www.4guysfromrolla.com/]
  ASPWorkshops.com [http://www.aspworkshops.com/]
  411ASP.NET Directory [http://www.411asp.net/]
  DevelopersDex.com [http://www.developersdex.com/]
  ASPObjects.com [http://www.aspobjects.com/Aspx_Scripts/]
  AngryCoder.com [http://www.angrycoder.com/]
  DotNetExperts.com [http://www.dotnetexperts.com/]
  Big-Boys.com [http://www.big-boys.com/aspnet/]
  Dot NET Books [http://www.dotnetbooks.com/]
  Dot NET Wire [http://www.dotnetwire.com/]
  DevX.com [http://www.devx.com/dotnet/]
  ASP 101 [http://www.asp101.com/aspplus/]
  ASP Wire [http://www.aspwire.com/]
  ASP Watch [http://www.aspwatch.com/]

ASP Computer Products
can be found at its new address: Click here [http://www.aspcomputerproducts.com/].

 

ASP.NET is a revolutionary new programming framework that enables the rapid development of powerful web applications and services. Part of the emerging Microsoft .NET Platform, it provides the easiest and most scalable way to build, deploy and run distributed web applications that can target any browser or device.

Step 1: Download and Install ASP.NET
The Beta 1 Release of ASP.NET is now available. This release is supported on Windows 2000 -- both server and workstation editions.
Click here to download ASP.NET and the .NET Framework SDK [http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml]
Also available as a separate download are the ASP.NET Mobile Controls. These enable developers to easily target mobile devices (WAP-enabled cell phones, Pocket PCs, etc) using ASP.NET.
Click here to download ASP.NET Mobile Web SDK [http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/516/msdncompositedoc.xml]

Step 2: Explore the Samples and Tutorials
The .NET Quickstart Tutorials include over 900 samples that demonstrate ASP.NET and the .NET Framework. They can be installed locally as part of the SDK, or run online from http://www.gotdotnet.com/quickstart [http://www.gotdotnet.com/quickstart].
We have also built comprehensive, end-to-end e-commerce and portal applications using ASP.NET and the .NET Framework. You can run and explore the source code online at http://www.ibuyspy.com/ [http://www.ibuyspy.com/].

Step 3: Join the Discussion Lists
There are a number of great e-mail-based discussion lists for ASP.NET. The Microsoft ASP.NET team regularly participates in the discussions and posts sample code.
To join the ASPNG discussion list (one of the most active 3rd party lists), select your preferences and submit the form below:
Your Email:  

List Name Topics (number of posts/day)
 aspngcommunity general posts and announcements (5)
 aspng general ASP.NET discussion forum (10)
 aspngbeta general ASP.NET technical discussion forum (30)
 aspngvs ASP.NET in Visual Studio.NET discussions (20)
 apngdata ADO.NET and data access discussions (15)
 aspngvb VB language discussions (10)
 aspngcs C# language discussions (10)
 aspngwebservices Web Services discussions (5)
 aspngconfig ASP.NET configuration discussions (5)
 aspngsecurity ASP.NET security discussions (5)
 aspngxml XML discussions (5)
 aspngmob ASP.NET mobile controls discussions (5)
 aspngarchitecture ASP.NET architecture discussions (5)
 aspngibuyspy www.ibuyspy.com discussions (10)

Click here to discover other discussion lists. [http://www.asp.net/discussions.aspx]


Copyright 2000 Microsoft Corporation


Source Code
<%
  Dim strFileName 
  strFileName = Server.MapPath("/demos/asp.net.html")

  Dim objFSO, objTS, strHTML
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  Set objTS = objFSO.OpenTextFile(strFileName)
  strHTML = objTS.ReadAll
  objTS.Close
  Set objTS = Nothing
  Set objFSO = Nothing

  Dim objRegExp
  Set objRegExp = new RegExp

  'Assume strHTML contains the HTML with the <a href="<i>URL</i>"><i>URL Description</i></a>
  'We want to store into strText the HTML in strHTML, but with the HREF tags
  'changed to a more text-friendly <i>URL Description</i> [<i>URL</i>]
  objRegExp.IgnoreCase = True
  objRegExp.Global = True
  objRegExp.Pattern = "<a\s+href=""http://(.*?)"">\s*((\n|.)+?)\s*</a>"

  'Now, replace the HREF tags with our preferred format
  strText = objRegExp.Replace(strHTML, "$2 [http://$1]")
  Response.Write(strText)

  Set objRegExp = Nothing
%>


[Return to the Article] | [View the SubMatches demo]