Find a string in an Array

Hi,

Is this a function in asp.net to find if a string exist in an array?

I have tried "Array.Exists(arrOptions, AddressOf GotOpt_Name)" and it works but is there some function like

arrOptions.Exists("Name")

in .NET?
LVL 17
NicksonKohAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
philipjonathanConnect With a Mentor Commented:
Sorry, it's a shared method:

If Array.IndexOf(arrOptions, "Name") > 0 Then
  ' Name is found
End If
0
 
M3mph15Commented:
Hi,

So i'm going to guess you want to find out if a certain string exists in an array. I'm not sure about that function but i know it can be done by looping through the array

E.g.
Boolean arrExists = new Boolean
arrExists = False
String var = <whatever string your looking for>
For i = 0 To <arrayname>.Count - 1 'Must use -1 because array index starts at 0
If <arrayname>(i).tostring() = var Then
      arrExists = True
End If
Next

If arrExists = True Then
       'Code for value exists in array
End If

HTH
-M3mph15
0
 
philipjonathanCommented:
Try:

If arrOptions.IndexOf("Name") > 0 Then
  ' Name is found
End If
0
 
NicksonKohAuthor Commented:
Thx. In the end, I still wrote a custom function because someone did a test and found a simple custom function is 75% faster!
0
All Courses

From novice to tech pro — start learning today.