Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42454

[RESOLVED] searching in a 2D array

$
0
0
I have an array like
Code:

        public static string[,] ColumnIndex = {
                                                  {"AcademicInterestCD1Act","25"},
                                                {"AcademicInterestCD1Act","25"},
                                                {"AcademicInterest1","26"}
                                              };

which is supposed to represent the column index (second field) for each column title (first field). I'm not sure if I'm even creating that array right.

I would like a function that I could call like GetColumnIndexOf("AcademicInterestCD1Act") and it would return 25, in this example.

It seems like this is something very trivial to do, but I don't know where to start. Most of the data processing I do is in SQL :blush:

Edit: I feel dumb, this was rather easy. Posting solution in case someone searches for this
Code:

        public static int GetColumnIndexOf(string searchString)
        {
            for (int i = 0; i <= ColumnIndex.GetUpperBound(0); i++)
            {
                if (ColumnIndex[i, 0] == searchString)
                {
                    return int.Parse(ColumnIndex[i, 1]);
                }
            }
            //if we got this far, there are no matches
            return -1;
        }


Viewing all articles
Browse latest Browse all 42454

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>