Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find a string in an Array

Posted on 2009-05-10
4
Medium Priority
?
828 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

877 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