Search a VBScript Array with Filter()

Filter() searches a one-dimensional array of strings and returns a zero-based array containing values that include or exclude the requested substring.

Syntax

Filter(sourceArray, match, include, compare)

include is optional: True returns matching elements and False returns non-matching elements. Use vbBinaryCompare for case-sensitive binary comparison or vbTextCompare for text comparison.

Search an array

Dim myArray(3), item, searchString, filtered
myArray(0) = "UK"
myArray(1) = "USA"
myArray(2) = "Canada"
myArray(3) = "UAE"

For Each item In myArray
    Response.Write item & "<br>"
Next

searchString = "UA"
filtered = Filter(myArray, searchString)

Response.Write "<br>-----After Filter------<br>"
For Each item In filtered
    Response.Write item & "<br>"
Next

Output

UK
USA
Canada
UAE

-----After Filter------
UAE

Case-insensitive matching

filtered = Filter(myArray, searchString, True, vbTextCompare)

Set include to False when you want the values that do not contain the match. Filter() performs substring matching; for searching within one string, use InStr().


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer