vb如何截取字符串

来源:百度知道 编辑:UC知道 时间:2024/07/03 22:14:36
我用common dialog控件选了某个程序,比如C:\Program Files\ghost\ui\2.exe,那么我要用截取字符串的方法找出2.exe的所在文件夹的路径即C:\Program Files\ghost\ui,如何实现,有个网友给我了这样的代码:pos = InStr(reverse(FileName), "\")
可我不会用,麻烦指点下,如何把截取的路径读到变量aaa内

Function GetFilePath(FileName As String, file) As String
Dim temp As String
temp = StrReverse(FileName)
pos = InStr(temp, "\")
file = StrReverse(left(temp, pos - 1))
GetFilePath = StrReverse(Mid(temp, pos))
End Function
用这个函数即可

pos = InstrRev(FileName, "\")
是取得最后一个\的位置,
路径就是

Private Sub Command1_Click()
FileName = "C:\Program Files\ghost\ui\2.exe"
pos = InStrRev(FileName, "\")
aaa = Left(FileName, pos - 1)
Print aaa

End Sub