Filter Code Example
This simple demo illustrates how to use the Filter function grab array elements that
correspond (or don't correspond) to a specified filter parameter...
The name list contains:
Scott, Steve, Yves, Charles, Ian, Mike, Christopher, Roger, Josh, Kevin, David, Isaac, John
The names that contain the letter 's':
Scott, Steve, Yves, Charles, Christopher, Josh, Isaac
The names that do not contain the letter 'c':
Steve, Yves, Ian, Mike, Roger, Josh, Kevin, David, John
The Source Code
'Create an array of names
Dim aNames
aNames = Array("Scott", "Steve", "Yves", "Charles", _
"Ian", "Mike", "Christopher", "Roger", _
"Josh", "Kevin", "David", "Isaac", "John")
'List the complete list of names:
Response.Write "<b>The name list contains:</b><br>"
Response.Write join(aNames, ", ")
'Now, filter on a certain character
Response.Write "<p><b>The names that contain the " & _
"letter 's':</b><br>"
Dim aNamesWithS
aNamesWithS = Filter(aNames, "s", True, vbTextCompare)
Response.Write join(aNamesWithS, ", ")
'Now, filter and display on another character
Response.Write "<p><b>The names that <i>do not</i> " & _
"contain the letter 'c':</b><br>"
Response.Write join(Filter(aNames, "c", False, vbTextCompare), ", ")
|
[Return to the Article]