vb6我如何编辑它以使扩展只计数到3个字符(字符串解析)

时间:2008-11-14 22:52:43

标签: vb6 string

有一天,有人发布了一个很棒的小功能,它将文件的完整路径分成几个部分,如下所示:

Function BreakDown(Full As String, FName As String, PName As String, Ext As String) As Integer
 If Full = "" Then
 BreakDown = False
 Exit Function
 End If
 If InStr(Full, "\") Then
 FName = Full
 PName = ""
 Sloc% = InStr(FName, "\")
 Do While Sloc% <> 0
   PName = PName + Left$(FName, Sloc%)
   FName = Mid$(FName, Sloc% + 1)
   Sloc% = InStr(FName, "\")
 Loop
 Else
 PName = ""
 FName = Full
 End If
Dot% = InStr(Full, ".")
If Dot% <> 0 Then
 Ext = Mid$(Full, Dot%)
Else
 Ext = ""
End If
BreakDown = True

End Function

但是,如果该行继续超过该点,则将其视为扩展的一部分,无论如何,在字符串的最后一个句点之后,是否只计算3个字符?

2 个答案:

答案 0 :(得分:1)

Dot% = InStrRev(Full, ".")  ' First . from end of string
If Dot% <> 0 Then
 Ext = Mid$(Full, Dot%, 3)
Else
 Ext = ""
End If

Mid $语法:Mid(string,start [,length])

答案 1 :(得分:0)

如果你只有空白字符,那么只需将其添加为第一行

Full = Trim(Full)

如果您有其他角色,那么

更改:

Ext = Mid$(Full, Dot%)

到:

Ext = Mid$(Full, Dot%, 3)