Click to See Complete Forum and Search --> : string question
lindawqu
October 3rd, 2001, 01:01 PM
I have a string (a url which is not fixed length) as follows:
http:\\www.yahoo.com\faq\my.jsp
I want to get 'my.jsp' from the whole string, that is, I want to the file name 'my.jsp'. It can be like
http:\\www.goto.com\ad\page1\you.html.
In this case, I want to get 'you.html'
Please tell me how to do it.
thanks
Boumxyz2
October 3rd, 2001, 01:14 PM
Is the file name length fixed ? If so you can use Filename = right(5,URL)
lindawqu
October 3rd, 2001, 01:29 PM
the file name and url are not fixed length.
Iouri
October 3rd, 2001, 01:44 PM
Using InStr function find the last "\" and everything to the right will be your file. It is the same how to extract file name from the path.
Iouri Boutchkine
iouri@hotsheet.com
DSJ
October 3rd, 2001, 01:53 PM
You can use an API if you strip the http: off the front... ie.
option Explicit
private Declare Function GetFileTitle Lib "comdlg32.dll" Alias "GetFileTitleA" (byval lpszFile as string, byval lpszTitle as string, byval cbBuf as Integer) as Integer
private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Buffer as string
Buffer = string(255, 0)
GetFileTitle "\\www.yahoo.com\faq\my.jsp", Buffer, len(Buffer)
Buffer = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)
MsgBox Buffer
End Sub
MKSa
October 3rd, 2001, 01:55 PM
filename = Right$(url, Len(url) - InStrRev(url, "\"))
Strat
October 3rd, 2001, 03:07 PM
Use the InStrRev function:
Dim url As String
url = "http:\\www.yahoo.com\faq\my.jsp"
url = Right(url, Len(mystr) - InStrRev(url, "\"))
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.