Solved

Find a string in an Array

Posted on 2009-05-10
4
821 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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