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
Printable View
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
Quote:
Originally Posted by Pouncer
VB Code:
Dim strName As String strName = "C:\hello.txt\" MsgBox Mid(strName, 1, InStrRev(strName, "\") - 1)
VB Code:
MsgBox Left$("C:\hello.txt\", (Len("C:\hello.txt\") - 1))
Whoops
VB Code:
Private Function ParseDir(ByVal strName As String) As String If Right$(strName, 1) = "\" Then ParseDir = Mid$(strName, 1, InStrRev(strName, "\") - 1) Else ParseDir = strName End If End Function
Jmacp, there is no need to give strName the same info twice in your example :D
VB Code:
Dim strName As String strName = "C:\hello.txt\" ' or text1.text If Right$(strName, 1) = "\" Then MsgBox Mid$(strName, 1, InStrRev(strName, "\") - 1) End If
EDIT: I see you changed your post :thumb:
What's wrong with the left function??Quote:
Originally Posted by lintz
VB Code:
Dim strName As String strName = "C:\hello.txt\" ' or text1.text If Right(strName, 1) = "\" Then MsgBox Left(strName, Len(strName) - 1) End If
Nothing wrong with the left function :D
nothing, same difference.Quote:
Originally Posted by yitzle