Searching inside an array for matching elements using Filter function.We can search inside an array for a string using Filter() built in function of VB used in ASP. The search or find operation will return another array with the result. We can use different arguments to match our requirement while using Filter function. This function works like different types of string functions like InStr, Replace etc. Here is the syntax of Filter() function.
Here my_array is our main array inside which we will be searching, search_string is the string variable or the string itself to be searched inside my_array. The other two arguments include and comparetype are optional arguments. include is a Boolean value, it can be True or False. If it is True then all matching elements of the my_array is returned and if it is set to False then all not matching elements are returned. The argument comparetype can take value of 0 or 1, if it is set to 0 then it is a binary comparison so it is case sensitive as a result lower and upper case letters are treated as different. If the value of comparetype is set to 1 then it will be a text comparison so it is case insensitive, as a result lower case and upper case text are treated as same.
Let us try with this simple code on how to use Filter function.
The output of the above code is here
By default the argument include is set to True and comparetype is set to 0. So if we search for lower case word ua ( in place of UA ), we will get empty result. We can add the value of these two optional arguments and see the result. The Filter function can be modified like this
You will get different results by making include = False and changing comparetype to 0. Similar function in ASP for searching an array is in_array()
This article is written by plus2net.com team.
Be the first to post comment on this article :