Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method to check array list containing specific string

Tags:

c#

silverlight

I have an ArrayList that import records from a database. Is there any method to check whether the arrayList contains schname that i want to match to another list which is an api?

List<PrimaryClass> primaryList = new List<PrimaryClass>(e.Result);
PrimaryClass sc = new PrimaryClass();
foreach (string item in str)
{
    for (int a = 0; a <= e.Result.Count - 1; a++)
    {
        string schname = e.Result.ElementAt(a).PrimarySchool;
        string tophonour = e.Result.ElementAt(a).TopHonour;
        string cca = e.Result.ElementAt(a).Cca;
        string topstudent = e.Result.ElementAt(a).TopStudent;
        string topaggregate = e.Result.ElementAt(a).TopAggregate;
        string topimage = e.Result.ElementAt(a).TopImage;        
        if (item.Contains(schname))
        {
        }
    }
}

This is what I have come up with so far, kindly correct any errors that I might have committed. Thanks.

like image 217
GJJ Avatar asked May 19 '11 06:05

GJJ


People also ask

How do you find a specific string in an ArrayList?

Get the array list. Using the for-each loop get each element of the ArrayList object. Verify whether each element in the array list contains the required string. If so print the elements.

How do you check if a string is present in array of strings?

You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't exist.

How do I check if a string contains a particular list?

The contains() method of List interface in Java is used for checking if the specified element exists in the given list or not.

How do you find a specific object in an ArrayList?

To check if ArrayList contains a specific object or element, use ArrayList. contains() method. You can call contains() method on the ArrayList, with the element passed as argument to the method. contains() method returns true if the object is present in the list, else the method returns false.


2 Answers

How about ArrayList.Contains?

like image 50
Kamyar Avatar answered Oct 12 '22 13:10

Kamyar


Try this

foreach( string row in arrayList){
    if(row.contains(searchString)){
       //put your code here.
    }
}
like image 23
Amit Gupta Avatar answered Oct 12 '22 15:10

Amit Gupta