Go4Expert (http://www.go4expert.com/)
-   Visual Basic [VB] (http://www.go4expert.com/articles/visual-basic-tutorials/)
-   -   URI Manipulation with .Net's URI Class (http://www.go4expert.com/articles/uri-manipulation-nets-uri-class-t3644/)

pradeep 27Mar2007 17:53

URI Manipulation with .Net's URI Class
Uniform Resource Identifiers (URIs) may represent Web requests, FTP requests, files, news, and e-mail. Whenever you need to work with URIs and determine a particular portion of a given URI, you can utilize the System.URI class available in Visual Studio .NET. This class allows you to represent and easily manipulate a given URI.

To create an example, add a ListBox control to your form and call it ListBox1. Then, add the code in Snippet A.

Snippet A

Code: VB

Private Sub GetURIInfo()
      Dim strURI As New Uri("http://www.go4expert.com/showthread.php?p=10432")
      With ListBox1.Items
          .Add("Scheme: " & strURI.Scheme)
          .Add("Host: " & strURI.Host)
          .Add("Path: " & strURI.AbsolutePath)
          .Add("Query: " & strURI.Query)
          .Add("Type: " & strURI.HostNameType.ToString())
          .Add("Port: " & strURI.Port)
      End With
  End Sub

In the code, we initially define a strURI variable and set its value to a link from the Go4Expert forums. Then, we add the following properties of the URI object strURI to the ListBox1 control: Scheme, Host, Path, Query, Type, Port. The ListBox1 control simply displays the selected properties of the strURI object.

All times are GMT +5.5. The time now is 15:56.