Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to extract various parts of URL using UrlGetPart API ?

Total Hit ( 5071)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Have you ever tried to extract various parts of URL....? If yes then you know how tedious it is. But in fact is very simple if you use API UrlGetPart.

Here is a simple example to use this API.

Step-By-Step Example

- Create a standard exe project
- Place the following code in form1

Click here to copy the following block
Private Const MAX_PATH    As Long = 260
Private Const ERROR_SUCCESS As Long = 0

Private Const URL_PART_SCHEME As Long = 1
Private Const URL_PART_HOSTNAME As Long = 2
Private Const URL_PART_USERNAME As Long = 3
Private Const URL_PART_PASSWORD As Long = 4
Private Const URL_PART_PORT As Long = 5
Private Const URL_PART_QUERY As Long = 6

Private Const URL_PARTFLAG_KEEPSCHEME As Long = &H1

Private Declare Function UrlGetPart Lib "shlwapi" Alias "UrlGetPartA" ( _
    ByVal pszIn As String, _
    ByVal pszOut As String, _
    pcchOut As Long, _
    ByVal dwPart As Long, _
    ByVal dwFlags As Long) As Long

Dim strURL As String

Private Sub Form_Load()
  strURL = "http://myusername:mypassword@www.mysite.com:5555/default.asp?Code=123"

  Debug.Print strURL & vbCrLf

  Debug.Print "SCHEME : " & GetUrlParts(strURL, URL_PART_SCHEME, 0&)
  Debug.Print "HOSTNAME : " & GetUrlParts(strURL, URL_PART_HOSTNAME, 0&)
  Debug.Print "USERNAME : " & GetUrlParts(strURL, URL_PART_USERNAME, 0&)
  Debug.Print "PASSWORD : " & GetUrlParts(strURL, URL_PART_PASSWORD, 0&)
  Debug.Print "PORT : " & GetUrlParts(strURL, URL_PART_PORT, 0&)
  Debug.Print "QUERY : " & GetUrlParts(strURL, URL_PART_QUERY, 0&)

End Sub

Private Function GetUrlParts(ByVal sUrl As String, _
               dwPart As Long, _
               dwFlags As Long) As String

  Dim sPart As String
  Dim dwSize As Long

  If Len(sUrl) > 0 Then
    sPart = Space$(MAX_PATH)
    dwSize = Len(sPart)

    If UrlGetPart(sUrl, _
        sPart, _
        dwSize, _
        dwPart, _
        dwFlags) = ERROR_SUCCESS Then

      GetUrlParts = Left$(sPart, dwSize)
    End If
  End If
End Function

Output :
http:myusername:mypassword@www.mysite.com:5555default.asp?Code123SCHEME:httpHOSTNAME:www.mysite.comUSERNAME:myusernamePASSWORD:mypasswordPORT:5555QUERY:Code12


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.