Solved

VB.Net - Find String in Array

Posted on 2016-10-12
3
47 Views
Last Modified: 2016-10-12
Good Day Experts!

I think what I want to do is possible but I am struggling how to get started and I hope you can point me in the right direction.

I have a Case statement that I would like to use a search of  arrayLists to determine which block of Case statement to run.
I have 3 different ArrayLists pre-populated.  I have a DataReader of Accounts  that I need to loop through and determine which block of code to run.  So if the Account is in ArrayList1 run this code, if Account is in ArrayList2 run this code etc...
The Account won't be in multiple ArrayLists.

Case "Account in ArrayList1 = yes"
     ....................

Case "Account in ArrayList2 = yes"
     ...................

Case "Account in ArrayList3 = yes"
     ...................


I have been searching the net for some time and am having a bit of trouble getting started.  Can you help?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41840200
You can use the .Contains() method to determine if a string is in an array.  Here's an example:

        Dim array1() = New String() {"yes", "no", "yes", "yes"}
        Dim array2() = New String() {"yes", "yes", "yes", "yes"}

        If array1.Contains("no") Then
            Console.WriteLine("array1")
        End If

        If array2.Contains("no") Then
            Console.WriteLine("array2")
        End If

        Console.ReadLine()

Open in new window


In this example, the console will read "array1" only.
0
 

Author Comment

by:Jimbo99999
ID: 41840237
Thank you. I have integrated .Contains and running the code now.
0
 

Author Closing Comment

by:Jimbo99999
ID: 41840286
Exactly what I was looking for. It works great!

Thanks,
jimbo99999
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

770 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