首页 / 软件开发 / VB / 从字符串中分离文件路径、文件名及其扩展名
从字符串中分离文件路径、文件名及其扩展名2010-03-12此函数从字符串中分离出路径Function ParsePath (sPathIn As String) As String
Dim I As Integer
For I = Len(sPathIn) To 1 Step -1
If InStr(":", Mid$(sPathIn, I, 1)) Then Exit For
Next
ParsePath = Left$(sPathIn, I)
End Function
此函数从字符串中分离出文件名Function ParseFileName (sFileIn As String) As String
Dim I As Integer
For I = Len(sFileIn) To 1 Step -1
If InStr("", Mid$(sFileIn, I, 1)) Then Exit For
Next
ParseFileName = Mid$(sFileIn, I + 1, Len(sFileIn) - I)
End Function
此函数从字符串中分离出文件扩展名Function GetFileExt (sFileName As String) As String
Dim P As Integer
For P = Len(sFileName) To 1 Step -1
If InStr(".", Mid$(sFileName, P, 1)) Then Exit For
Next
GetFileExt = Right$(sFileName, Len(sFileName) - P)
End Function