VB 版 (精华区)
发信人: bloom (├┝┞┟┠┢┣), 信区: VB
标 题: 取得文件的扩展名
发信站: 哈工大紫丁香 (2000年09月11日21:02:54 星期一), 站内信件
取得文件的扩展名
Function GetExtension(Filename As String)
Dim PthPos, ExtPos As Integer
For i = Len(Filename) To 1 Step -1 ' Go from the Length of the filename, to
the first character by 1.
If Mid(Filename, i, 1) = "." Then ' If the current position is '.' then...
ExtPos = i ' ...Change the ExtPos to the number.
For j = Len(Filename) To 1 Step -1 ' Do the Same...
If Mid(Filename, j, 1) = "\" Then ' ...but for '\'.
PthPos = j ' Change the PthPos to the number.
Exit For ' Since we found it, don't search any more.
End If
Next j
Exit For ' Since we found it, don't search any more.
End If
Next i
If PthPos > ExtPos Then
Exit Function ' No extension.
Else
If ExtPos = 0 Then Exit Function ' If there is not extension, then exit sub.
GetExtension = Mid(Filename, ExtPos + 1, Len(Filename) - ExtPos) 'Messagebox
the Extension
End If
End Function
使用:
FileExt = GetExtension("c:\windows\vb\vb.exe")
返回
--
├┝┞┟┠┢┣◣◢
∣
▆▆▆
▇▇
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.170.211]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.404毫秒