Parsing URL

Results 1 to 2 of 2

Thread: Parsing URL

  1. #1
    Join Date
    Dec 1969
    Posts
    760

    Default Parsing URL

    Is there a way to parse a URL? I would like to know which directory a file is in and what the name of that file is. Example: http://www.somewhere.com/folder/file.asp - I would like to read &#039folder&#039 into a variable and &#039file&#039.<BR><BR>Thanks in advance<BR>Andrew<BR>andrew@bailey-macmillan.com

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Parsing URL

    Just an idea, don&#039t have time to code this, but do the following:<BR><BR>1.) Get rid of "//"<BR>2.) Split on "/"<BR><BR>Dim strURL<BR>strURL = "http://www.somewhere.com/folder/file.asp<BR><BR>&#039Step 1<BR>strURL = Replace(strURL,"//","")<BR><BR>&#039Step 2<BR>Dim aURL<BR>aURL = split(strURL,"/")<BR><BR><BR>&#039Now, if there are three elements, then we have a file and folder. If there are two, just a file<BR><BR>If UBound(aURL) - LBound(aURL) = 3 then<BR> strFile = aURL(UBound(aURL))<BR> strFolder = aURL(UBound(aURL) - 1)<BR>elseif UBound(aURL) - LBound(aURL) = 2 then<BR> strFile = aURL(UBound(aURL))<BR>end if<BR><BR><BR>Hope this helps (and works!) :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •