Fonction de filtre VBScript
❮ Référence complète de VBScriptLa fonction Filter renvoie un tableau de base zéro qui contient un sous-ensemble d'un tableau de chaînes basé sur un critère de filtre.
Remarque : Si aucune correspondance du paramètre value n'est trouvée, la fonction Filter renverra un tableau vide.
Remarque : Si le paramètre inputstrings est Null ou n'est PAS un tableau unidimensionnel, une erreur se produit.
Syntaxe
Filter(inputstrings,value[,include[,compare]])
Parameter | Description |
---|---|
inputstrings | Required. A one-dimensional array of strings to be searched |
value | Required. The string to search for |
include | Optional. A Boolean value that indicates whether to return the substrings that include or exclude value. True returns the subset of the array that contains value as a substring. False returns the subset of the array that does not contain value as a substring. Default is True. |
compare | Optional. Specifies the string comparison to use. Can have one of the following values:
|
Exemples
Exemple 1
Filtre : éléments contenant "S"
<%
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S")
for each x in b
response.write(x & "<br />")
next
%>
La sortie du code ci-dessus sera :
Sunday
Saturday
Exemple 2
Filtre : éléments qui ne contiennent PAS "S" (include=False) :
<%
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False)
for each x in b
response.write(x & "<br />")
next
%>
La sortie du code ci-dessus sera :
Monday
Tuesday
Wednesday
Thursday
Friday
Exemple 3
Filtre : les éléments qui contiennent "S", avec une comparaison textuelle (comparer=1) :
<%
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
response.write(x & "<br />")
next
%>
La sortie du code ci-dessus sera :
Sunday
Tuesday
Wednesday
Thursday
Saturday
❮ Référence complète de VBScript