|
-
Dec 3rd, 2005, 04:04 PM
#1
Thread Starter
Frenzied Member
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
-
Dec 3rd, 2005, 04:16 PM
#2
Re: simple string parse help
 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:
Dim strName As String
strName = "C:\hello.txt\"
MsgBox Mid(strName, 1, InStrRev(strName, "\") - 1)
-
Dec 3rd, 2005, 04:17 PM
#3
Re: simple string parse help
VB Code:
MsgBox Left$("C:\hello.txt\", (Len("C:\hello.txt\") - 1))
-
Dec 3rd, 2005, 04:23 PM
#4
Re: simple string parse help
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
Last edited by Jmacp; Dec 3rd, 2005 at 04:28 PM.
-
Dec 3rd, 2005, 04:26 PM
#5
Re: simple string parse help
Jmacp, there is no need to give strName the same info twice in your example
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
-
Dec 4th, 2005, 02:58 AM
#6
Addicted Member
Re: simple string parse help
 Originally Posted by lintz
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
What's wrong with the left function??
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
-
Dec 4th, 2005, 03:00 AM
#7
Re: simple string parse help
Nothing wrong with the left function
-
Dec 4th, 2005, 04:12 AM
#8
Re: simple string parse help
 Originally Posted by yitzle
What's wrong with the left function??
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, 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|