Solved

Find a string in an Array

Posted on 2009-05-10
4
823 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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