'增强版Filter函数,添加匹配起始位置参数StartPos
'StartPos=0,从数组元素左侧起匹配
'StartPos=1,从数组元素右侧起匹配
'StartPos=2,不限定匹配的起始位置
Public Function TArr(OArr() As String, InputTXT As String, Optional CTF As Boolean = True, Optional StartPos As Integer = 0) As String()
Dim i As Long
Dim j As Long
Dim l As Integer
Dim aBuff() As String
l = Len(InputTXT)
If (StartPos = 2) Then
aBuff = Filter(OArr(), InputTXT, CTF)
Else
i = -1
j = -1
If CTF Then
If (StartPos = 0) Then
Do While i <= UBound(OArr) - 1
i = i + 1
If InStr(OArr(i), InputTXT) = 1 Then
j = j + 1
ReDim Preserve aBuff(j)
aBuff(j) = OArr(i)
End If
Loop
Else
Do While i <= UBound(OArr) - 1
i = i + 1
If InStrRev(OArr(i), InputTXT) = Len(OArr(i)) - l + 1 Then
j = j + 1
ReDim Preserve aBuff(j)
aBuff(j) = OArr(i)
End If
Loop
End If
Else
If (StartPos = 0) Then
Do While i <= UBound(OArr) - 1
i = i + 1
If InStr(OArr(i), InputTXT) <> 1 Then
j = j + 1
ReDim Preserve aBuff(j)
aBuff(j) = OArr(i)
End If
Loop
Else
Do While i <= UBound(OArr) - 1
i = i + 1
If InStrRev(OArr(i), InputTXT) <> Len(OArr(i)) - l + 1 Then
j = j + 1
ReDim Preserve aBuff(j)
aBuff(j) = OArr(i)
End If
Loop
End If
End If
End If
TArr = aBuff
End Function
VB6 Advanced Filter Function
最新推荐文章于 2024-04-18 08:00:00 发布