Results 1 to 7 of 7

Thread: Cutting Strings

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Cutting Strings

    Hi,

    Ok, I have this string:

    VB Code:
    1. Dim MyString As String
    2. MyString = "C:\Project\code.cpp"

    I need to know how to remove the pathway in the string and leave just the filename.

    If anyone could help I'd appreciate it.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Cutting Strings

    VB Code:
    1. Debug.Print Mid$(MyString, InStrRev(MyString, "\") + 1)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Re: Cutting Strings

    Thanks, but I tried that and it doesn't work lol.

    ???

  4. #4
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Re: Cutting Strings

    Hes code works fine for me. Here is another way you can do it, using the Split function.
    VB Code:
    1. Private Sub Form_Load()
    2. Dim MyString As String
    3. Dim strSplit() As String
    4. MyString = "C:\Project\code.cpp"
    5.  
    6. strSplit = Split(MyString, "\")
    7. MsgBox strSplit(UBound(strSplit))
    8. End Sub
    Are we alive or just breathing?

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Cutting Strings

    Check out my URL/Path Manipulation functions

    Should be a few there that can help you out.

    I think:
    VB Code:
    1. MsgBox RemoveRootName(MyString, True)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Re: Cutting Strings

    Thanks a lot penagate, it worked a charm.

    Oh and thanks to Piller for contributing as well.

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Cutting Strings

    what was wrong with the solution I suggested? How was it not working? Penagate's code might be a bit of overkill in your situation.

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