Results 1 to 8 of 8

Thread: simple string parse help

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    simple string parse help

    hey guys i need to return the directory name without the last \ at the end..

    e..g.

    name = "C:\hello.txt\"

    should give me

    C:\hello.txt

    i tried MsgBox Right(Text5.Text, CInt(Len(Text5.Text) - 1)) but it doesnt work for some strings like this

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: simple string parse help

    Quote Originally Posted by Pouncer
    hey guys i need to return the directory name without the last \ at the end..

    e..g.

    name = "C:\hello.txt\"

    should give me

    C:\hello.txt

    i tried MsgBox Right(Text5.Text, CInt(Len(Text5.Text) - 1)) but it doesnt work for some strings like this
    VB Code:
    1. Dim strName As String
    2.     strName = "C:\hello.txt\"
    3.     MsgBox Mid(strName, 1, InStrRev(strName, "\") - 1)

  3. #3
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: simple string parse help

    VB Code:
    1. MsgBox Left$("C:\hello.txt\", (Len("C:\hello.txt\") - 1))

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: simple string parse help

    Whoops

    VB Code:
    1. Private Function ParseDir(ByVal strName As String) As String
    2.  
    3.     If Right$(strName, 1) = "\" Then
    4.         ParseDir = Mid$(strName, 1, InStrRev(strName, "\") - 1)
    5.     Else
    6.         ParseDir = strName
    7.     End If
    8.    
    9. End Function

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: simple string parse help

    Jmacp, there is no need to give strName the same info twice in your example

    VB Code:
    1. Dim strName As String
    2.     strName = "C:\hello.txt\"  ' or text1.text
    3.     If Right$(strName, 1) = "\" Then
    4.         MsgBox Mid$(strName, 1, InStrRev(strName, "\") - 1)
    5.     End If

    EDIT: I see you changed your post

  6. #6
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    Re: simple string parse help

    Quote Originally Posted by lintz
    VB Code:
    1. Dim strName As String
    2.     strName = "C:\hello.txt\"  ' or text1.text
    3.     If Right$(strName, 1) = "\" Then
    4.         MsgBox Mid$(strName, 1, InStrRev(strName, "\") - 1)
    5.     End If
    What's wrong with the left function??
    VB Code:
    1. Dim strName As String
    2.     strName = "C:\hello.txt\"  ' or text1.text
    3.     If Right(strName, 1) = "\" Then
    4.         MsgBox Left(strName, Len(strName) - 1)
    5.     End If

  7. #7
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: simple string parse help

    Nothing wrong with the left function

  8. #8
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: simple string parse help

    Quote Originally Posted by yitzle
    What's wrong with the left function??
    VB Code:
    1. Dim strName As String
    2.     strName = "C:\hello.txt\"  ' or text1.text
    3.     If Right(strName, 1) = "\" Then
    4.         MsgBox Left(strName, Len(strName) - 1)
    5.     End If
    nothing, same difference.

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