Last active
October 4, 2022 12:42
-
-
Save gwobcke/1044367 to your computer and use it in GitHub Desktop.
Classic ASP Check If In Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
Function in_array(element, arr, performTrim) | |
Dim i | |
in_array = False | |
For i=0 To Ubound(arr) | |
If performTrim Then '//there are some scenarios where you want to trim | |
If Trim(arr(i)) = Trim(element) Then | |
in_array = True | |
Exit Function | |
End If | |
Else '//and other scenarios where you don't | |
If arr(i) = element Then | |
in_array = True | |
Exit Function | |
End If | |
End If | |
Next | |
End Function | |
DIM findThis | |
findThis = "Apple" | |
fruits = Array("Banana","Apple","Orange") | |
If in_array(findThis, fruits, false) Then | |
Response.Write findThis & " is in the array" | |
Else | |
Response.Write findThis & " is not in the array" | |
End If | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, It is very useful for my work