vb 字符串操作问题

来源:百度知道 编辑:UC知道 时间:2024/06/02 21:09:30
有一个关于文件路径的字符串,如“e:\pjp\caxa\dama\oo.txt”
我想得到最后一个“\”之前的内容(包括“\”),即想得到“e:\pjp\caxa\dama\”,由于是路径,前面不知道有多少个“\”,但总之是想要去掉最后一个“\”之后的内容,而返回留下的内容,应该怎么做
谢谢

Dim fpath As String
fpath = "e:\pjp\caxa\dama\oo.txt"
While Right(fpath, 1) <> "\"
fpath = Left(fpath, Len(fpath) - 1)
Wend
Msgbox fpath

s1 = "e:\pjp\caxa\dama\1.tt"
i = Len(s1)
For i = Len(s1) To 1 Step -1
If Mid(s1, i, 1) = "\" Then
s1 = Left(s1, i)
Exit For
End If
Next i

Option Explicit

Private Sub Form_Load()
Show
Dim i
Dim T
Dim S
T = "e:\pjp\caxa\dama\oo.txt"
For i = 1 To Len(T) - 1
If Mid(T, Len(T) - i, 1) = "\" Then
S = Left(T, Len(T) - i)
Exit For
End If
Next i
Print S
End Sub

Public Function GetPathSTR(ByVal PATHandNAME As String, Optional ByRef FileName As String) As String
'注释:把带有含有文件和路径的字符串PA