How to Find an Element in an Array

I have the following multidimensional array:

        arrPreFlopRec[1, 1] = "A";
        arrPreFlopRec[2, 1] = "A";
        arrPreFlopRec[3, 1] = "A";
        arrPreFlopRec[4, 1] = "A";
        arrPreFlopRec[5, 1] = "A";
        arrPreFlopRec[6, 1] = "A";
        arrPreFlopRec[7, 1] = "A";
        arrPreFlopRec[8, 1] = "A";
        arrPreFlopRec[9, 1] = "B";

        arrPreFlopRec[1, 2] = "AA";
        arrPreFlopRec[2, 2] = "AA";
        arrPreFlopRec[3, 2] = "KK";
        arrPreFlopRec[4, 2] = "QQ";
        arrPreFlopRec[5, 2] = "AKs";
        arrPreFlopRec[6, 2] = "KK";
        arrPreFlopRec[7, 2] = "QQ";
        arrPreFlopRec[8, 2] = "AKs";
        arrPreFlopRec[9, 2] = "JJ";
       
        arrPreFlopRec[1, 3] = "N";
        arrPreFlopRec[2, 3] = "Y";
        arrPreFlopRec[3, 3] = "Y";
        arrPreFlopRec[4, 3] = "Y";
        arrPreFlopRec[5, 3] = "Y";
        arrPreFlopRec[6, 3] = "N";
        arrPreFlopRec[7, 3] = "N";
        arrPreFlopRec[8, 3] = "N";
        arrPreFlopRec[9, 3] = "N";

I need to find the row where  column 2 ="KK" and collumn 3 = "Y"
correct answer is row 3 .(arrPreFlopRec[3, 2] ,arrPreFlopRec[3,3]

 string strCombo = "KK";
 string strRaised = "Y";
 // Find the array elements:
      for (int i=0; i < 10; i++)
         for (int j=0; j < 5; j++)
// I need help with this
   if (arrPreFlopRec[i,j] == strCombo && arrPreFlopRec[i,j] == strRaised )
        {
         // Row found
         // Do Something
        }  
DovbermanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
string strCombo = "KK";
 string strRaised = "Y";

//columns that have to be found
int col1 = 2;
int col2 = 3;

      for (int i=0; i < 10; i++)
      if (arrPreFlopRec[i,col1] == strCombo && arrPreFlopRec[i,col2] == strRaised )
        {
         // Row found
         // Do Something
        }  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DovbermanAuthor Commented:
I do not know which columns need to be found.  I am searching for the column and row numbers that
contain the strings "KK" and "Y" in the same row.

The search probably needs a drill down statement
for (int j=0;j < 4; j++)

I just need to know how to do this.


0
als315Commented:
string strCombo = "KK";
 string strRaised = "Y";
 int match = 0;
      for (int i=0; i < 10; i++) {
         match = 0;
         for (int j=0; j < 5; j++) {
            if (arrPreFlopRec[i,j] == strCombo or arrPreFlopRec[i,j] == strRaised )      
            {
                     match++;
            }
         }
         if match > 1
         {
                 // Row found
               // Do Something
         }  
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

als315Commented:
If you need row and column:
 
string strCombo = "KK";
 string strRaised = "Y";
 int row = -1;
 int col1 = -1;
 int col2 = -1;
      for (int i=0; i < 10; i++) {
         row = i;
         col1 = -1;
         col2 = -1;
         for (int j=0; j < 5; j++) {
            if (arrPreFlopRec[i,j] == strCombo){
              col1 = j;
            }
            if (arrPreFlopRec[i,j] == strRaised )       
            {
              col2 = j;              
            } 
         }
         if (col1 >= 0 and col2 >=0 )
         {
               // Row found
               // Do Something
         }

Open in new window

I hope you can't have more then one appearance of "KK" or "Y" in one row
0
AndyAinscowFreelance programmer / ConsultantCommented:
string strCombo = "KK";
 string strRaised = "Y";


      for (int i=0; i < 10; i++)
{
  for(int j = 0; j < 5; j++)
  {
      if (arrPreFlopRec[i,j] == strCombo || arrPreFlopRec[i,j] == strRaised )
        {
//found one, now check for the other
for(int k = 0; k < 5; k++)
{
      if (arrPreFlopRec[i,k] == strCombo || arrPreFlopRec[i,k] == strRaised )
  {
    //a second match - the pairing is found
  }
}
        }  
  }
}
0
DovbermanAuthor Commented:
These may work. I am testing and will reply this afternoon.

Thanks,
0
DovbermanAuthor Commented:
Thanks for your guidance.
0
DovbermanAuthor Commented:
Thanks for your guidance.
This is the code I used:    

  string strCombo = "KK";
        string strRaised = "Y";

        int intMatch = 0;
        int intColCtr = 0;
        int intMatchRow1 = 0;
        int intMatchRow2 = 0;
        intMatch = 0;
        string strRaised1 = "";
        string strRaised2 = "";
        string strUnRaisedRec = "";
        string strRaisedRec = "";

        // There are always 2 rows that contain the specified
        // value of strCombo.
        // Find both matches for strCombo
        for (int intRowCtr = 0; intRowCtr < 10; intRowCtr++)
        {
   
            if (arrPreFlopRec[intRowCtr, 2] == strCombo )
            {
                intMatch++;

                if (intMatch >= 0)
                {
                    // Store value of column3
                    strRaised = arrPreFlopRec[intRowCtr, 3];
                   
                    // Store value of column 4
                    if (strRaised == "N")
                    {
                        strUnRaisedRec = arrPreFlopRec[intRowCtr, 4];
                    }

                    if (strRaised == "Y")
                    {
                        strRaisedRec = arrPreFlopRec[intRowCtr, 4];
                    }
                }  //  End if (intMatch >= 0)
            }  // End if (arrPreFlopRec[intRowCtr, 2] == strCombo )
        }  // End of row parsing for (int intRowCtr = 0; intRowCtr < 10; intRowCtr++)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.