Filter()
函数返回一个基于零的数组,其中包含基于特定过滤条件的字符串数组的子集。
语法
Filter(inputstrings,value[,include[,compare]])
参数说明
- Inputstrings - 必需的参数。该参数对应于要搜索的字符串数组。
- Value - 必需的参数。此参数对应于要根据
inputstrings
参数搜索的字符串。 - Include - 一个可选参数。这是一个布尔值,它指示是否返回包含或排除的子字符串。
- Compare - 一个可选参数。该参数描述要使用哪种字符串比较方法。
- 0 = vbBinaryCompare - 执行二进制比较
- 1 = vbTextCompare - 执行文本比较
例子
添加一个模块,并添加以下代码 -
Private Sub Constant_demo_Click()
Dim a,b,c,d as Variant
a = array("Red","Blue","Yellow")
b = Filter(a,"B")
c = Filter(a,"e")
d = Filter(a,"Y")
For each x in b
msgbox("The Filter result 1: " & x)
Next
For each y in c
msgbox("The Filter result 2: " & y)
Next
For each z in d
msgbox("The Filter result 3: " & z)
Next
End Sub
当执行上面的函数时,它会产生下面的输出。
The Filter result 1: Blue
The Filter result 2: Red
The Filter result 2: Blue
The Filter result 2: Yellow
The Filter result 3: Yellow
上一篇:
VBA数组
下一篇:
VBA用户自定义函数