|
-
Feb 15th, 2001, 10:44 AM
#1
Thread Starter
Junior Member
Has anyone seen a function for VB 5 that would return the filename from a URL string?
Any help appreciated!
Shaun.
-
Feb 15th, 2001, 02:34 PM
#2
Try this:
Code:
'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
-
Feb 16th, 2001, 05:52 AM
#3
Thread Starter
Junior Member
Many thanks!
Nice one, sir!
I think that´ll do the trick. nicely...
Very kind of you to take the time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|