Skip to content

Instantly share code, notes, and snippets.

@sergioruizdeveloper
Forked from gwobcke/checkIfInArray.asp
Created October 4, 2022 12:42
Show Gist options
  • Save sergioruizdeveloper/8e4eddfbd5372ecac77f05c9af39b3db to your computer and use it in GitHub Desktop.
Save sergioruizdeveloper/8e4eddfbd5372ecac77f05c9af39b3db to your computer and use it in GitHub Desktop.
Classic ASP Check If In Array
<%
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