PDA

Click to See Complete Forum and Search --> : Return filename from URLString function...anyone?


shaunmccallig
Feb 15th, 2001, 09:44 AM
Has anyone seen a function for VB 5 that would return the filename from a URL string?

Any help appreciated!

Shaun.

Feb 15th, 2001, 01:34 PM
Try this:


'Author: Iain17
'Origin: String Manipulation
'Purpose: InStrRev for VB5
'VB version: VB4/VB5/VB6
'Comments: Remove the Optional iStart As Long in order for this to work in VB4.


Private Function InStrRev2(strStringToSearch As String, strFind As String, Optional iStart As Long) As Long
Dim ip1 As Long, ip2 As Long
Dim iLenStringToSearch As Long
Dim iLenFind As Long

'get the length of the String
iLenStringToSearch = Len(strStringToSearch)
iLenFind = Len(strFind)

'if the start is 0 Then Set the start to the length
'of the String
If iStart = 0 Then
iStart = iLenStringToSearch
End If
iStart = iStart + 1

ip1 = 1
Do
ip2 = InStr(ip1, strStringToSearch, strFind)
If (ip2 > 0) And (ip2 + iLenFind <= iStart) Then
'if ip2 Is Not zero And it Is less than the
'place To start searching + the length of the
'find String Then Set the Function
'to Return that position
InStrRev2 = ip2
ElseIf ip2 = 0 Then
ip2 = iLenStringToSearch
End If
'set the Next position To seracf from
ip1 = ip2 + 1
Loop Until ip1 >= iStart

End Function


Usage


Private Sub Command1_Click()

strURL = "http:/www.site.com/file.zip"
MsgBox Mid(strURL, InStrRev2(strURL, "/") + 1)

End Sub

shaunmccallig
Feb 16th, 2001, 04:52 AM
Nice one, sir!

I think thatīll do the trick. nicely...

Very kind of you to take the time.