inarray function or method for ASP

by Nirmala 2009-11-25 18:54:47

inArray Method
in_array function is used to check whether given string is available in an array or not.
<%
Function in_array(element, arr)
For i=0 To Ubound(arr)
If Trim(arr(i)) = Trim(element) Then
in_array = True
Exit Function
Else
in_array = False
End If
Next
End Function
%>
Example:
The below example will help you to check the given string (Blue) is available in an array or not.

<%
Function in_array(element, arr)
For i=0 To Ubound(arr)
If Trim(arr(i)) = Trim(element) Then
in_array = True
Exit Function
Else
in_array = False
End If
Next
End Function
str = "Blue"
colors = Array("Red","Green","Blue","Black","White")
If in_array(str,colors) Then
Response.Write str & " is in the array"
Else
Response.Write str & " is not in the array"
End If
%>

Tagged in:

1743
like
1
dislike
0
mail
flag

You must LOGIN to add comments