Results 1 to 5 of 5

Thread: [RESOLVED] [2005] finding the last "/" in a string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    Resolved [RESOLVED] [2005] finding the last "/" in a string

    im using visual studio 2005

    ok say i have a string

    "/jason/jason/end.htm"

    and i want to pull everything from the last "/" and to the left and get rid of the end.htm

    i know there is the function instr() but not sure how i would use it in this case.

    any help appreciated.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,712

    Re: [2005] finding the last "/" in a string

    this code will return everything to the right of the last /
    VB Code:
    1. dim s as String  = MyString.SubString(MyString.LastIndexOf("/"c)+1)
    at least I think thats it
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    Re: [2005] finding the last "/" in a string

    hmm i dont exactly understand that code could u break it down for me?

  4. #4
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: [2005] finding the last "/" in a string

    Dim myString As String = "/jason/jason/end.htm"
    Dim intRemainingCharCount As Integer

    ' Gets the count of how many characters there are after the last '/'.
    intRemainingCharCount = myString.Length - (myString.LastIndexOf("/"c) + 1)

    ' Removes everything starting at the last '/' till the end of the string.
    myString = myString.Remove(myString.LastIndexOf("/"c) + 1, intRemainingCharCount)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    Re: [2005] finding the last "/" in a string

    thanks man worked like a charm

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