Solved

Find a string in an Array

Posted on 2009-05-10
4
819 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:NicksonKoh
  • 2
4 Comments
 
LVL 6

Expert Comment

by:M3mph15
ID: 24351315
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
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24351343
Try:

If arrOptions.IndexOf("Name") > 0 Then
  ' Name is found
End If
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 250 total points
ID: 24351347
Sorry, it's a shared method:

If Array.IndexOf(arrOptions, "Name") > 0 Then
  ' Name is found
End If
0
 
LVL 17

Author Closing Comment

by:NicksonKoh
ID: 31580016
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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get the web content with different encodings 2 46
imap read mail 1 30
Modal Popup Extender control 1 22
Get number of Files in Directory and Sub Directories 2 42
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question