CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: string question

  1. #1
    Join Date
    Jul 2001
    Posts
    430

    string question

    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


  2. #2
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: string question

    Is the file name length fixed ? If so you can use Filename = right(5,URL)



    Nicolas Bohemier

  3. #3
    Join Date
    Jul 2001
    Posts
    430

    Re: string question

    the file name and url are not fixed length.


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: string question

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: string question

    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: [email protected]
    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






  6. #6
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: string question

    filename = Right$(url, Len(url) - InStrRev(url, "\"))



  7. #7
    Join Date
    Aug 2000
    Posts
    27

    Re: string question

    Use the InStrRev function:

    Dim url As String

    url = "http:\\www.yahoo.com\faq\my.jsp"
    url = Right(url, Len(mystr) - InStrRev(url, "\"))



Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured